<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Text aus .txt oder string finden und löschen]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe zu dem Thema bereits viel gegooglet und auch die Boardsuche benutzt, die Ergebnisse fielen jedoch spärlich aus...</p>
<p>Ich hoffe, jemand von euch kann mir das beantworten:</p>
<p>Ich würde gerne ein Wort in einer txt-datei oder in einem string suchen und löschen lassen.</p>
<p>Als OS benutze ich Windows XP mit Dev-Cpp als IDE, falls das von Bedeutung ist.</p>
<p>Wäre über 'ne schnelle Antwort dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/181831/text-aus-txt-oder-string-finden-und-löschen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 10:24:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/181831.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 May 2007 20:06:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 20:06:08 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe zu dem Thema bereits viel gegooglet und auch die Boardsuche benutzt, die Ergebnisse fielen jedoch spärlich aus...</p>
<p>Ich hoffe, jemand von euch kann mir das beantworten:</p>
<p>Ich würde gerne ein Wort in einer txt-datei oder in einem string suchen und löschen lassen.</p>
<p>Als OS benutze ich Windows XP mit Dev-Cpp als IDE, falls das von Bedeutung ist.</p>
<p>Wäre über 'ne schnelle Antwort dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287021</guid><dc:creator><![CDATA[sarglord]]></dc:creator><pubDate>Thu, 17 May 2007 20:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 20:20:32 GMT]]></title><description><![CDATA[<p>naja - der übliche weg ist die datei einlesen, die datei ohne den string neu schreiben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287029</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Thu, 17 May 2007 20:20:32 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 20:22:30 GMT]]></title><description><![CDATA[<p>Könntest du mir daür evtl. ein kleines code-Beispiel geben?<br />
Wüsste jetzt nicht, wie ich das machen soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287031</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287031</guid><dc:creator><![CDATA[sarglord]]></dc:creator><pubDate>Thu, 17 May 2007 20:22:30 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 20:26:31 GMT]]></title><description><![CDATA[<p>Pseudo<br />
vector&lt;string&gt; lines;<br />
open file<br />
string line<br />
getline(file, line)<br />
replace in line if string found<br />
lines.push_back(line);<br />
close file</p>
<p>open file<br />
for every item in lines<br />
file &lt;&lt; lines[item] &lt;&lt; std::endl;<br />
close file</p>
<p>so in etwa <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287036</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287036</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Thu, 17 May 2007 20:26:31 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 20:39:25 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iterator&gt;
using namespace std;

int main(int argc, char ** argv) {
	if(argc!=3) {
		cout &lt;&lt; &quot;Dieses Programm entfernt alle Vorkommen eines Wortes aus einer Datei\n&quot;
				&quot;Und gibt den neuen Inhalt aus\n&quot;
				&quot;Bitte per &lt;prog&gt; &lt;datei&gt; &lt;wort&gt; starten&quot; &lt;&lt; endl;
		return 0;
	}
	string data;
	string find_s(argv[2]);

	ifstream file(argv[1]);

	file.unsetf(ios::skipws);

	data.assign(istream_iterator&lt;char&gt;(file), istream_iterator&lt;char&gt;());

	file.close();

	int pos=0;
	while( (pos=data.find(find_s))!=string::npos) 
		data.erase(pos, find_s.length());

	cout &lt;&lt; data;
	return 0;
}
</code></pre>
<p>das wieder in die datei schreiben dürfte einfach sein ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287044</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Thu, 17 May 2007 20:39:25 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 20:52:20 GMT]]></title><description><![CDATA[<p>Danke schonmal.</p>
<p>Da ich ja noch programmier-anfänger bin, nehme ich mir morgen mal die Zeit um den doch recht langen code zu verstehen und anzuwenden. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287055</guid><dc:creator><![CDATA[sarglord]]></dc:creator><pubDate>Thu, 17 May 2007 20:52:20 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 21:04:47 GMT]]></title><description><![CDATA[<p>hier nochmal mit mehr comments</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iterator&gt;
using namespace std;

int main(int argc, char ** argv) {
	if(argc!=3) {
		cout &lt;&lt; &quot;Dieses Programm entfernt alle Vorkommen eines Wortes aus einer Datei\n&quot;
				&quot;Und gibt den neuen Inhalt aus\n&quot;
				&quot;Bitte per &lt;prog&gt; &lt;datei&gt; &lt;wort&gt; starten&quot; &lt;&lt; endl;
		return 0;
	}
	string data;
	string find_s(argv[2]); // der string den wir suchen

	ifstream file(argv[1]); // öffnet die datei aus dem ersten argument

	file.unsetf(ios::skipws); // stellt das überspringen von whitespace ab

	data.assign( // zuweisung von daten an den data string
             istream_iterator&lt;char&gt;(file), //anfang der datei
             istream_iterator&lt;char&gt;()); // ende der datei

	file.close();

	int pos=0;

        // solange wie der zu entfernende string vorhanden: 
        //     entferne ihn einmal
	while( (pos=data.find(find_s))!=string::npos) 
		data.erase(pos, find_s.length());

	cout &lt;&lt; data;
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1287063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287063</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Thu, 17 May 2007 21:04:47 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 21:13:19 GMT]]></title><description><![CDATA[<p>@r0nny ... dann such auch erst wieder ab der stelle an der der String das letzte mal gefunden wurde ... ist etwas viel performanter. ..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287072</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Thu, 17 May 2007 21:13:19 GMT</pubDate></item><item><title><![CDATA[Reply to Text aus .txt oder string finden und löschen on Thu, 17 May 2007 22:29:15 GMT]]></title><description><![CDATA[<p>dann her mit dem schnelleren suchen !</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iterator&gt;
using namespace std;

int main(int argc, char ** argv) {
	if(argc!=3) {
		cout &lt;&lt; &quot;Dieses Programm entfernt alle Vorkommen eines Wortes aus einer Datei\n&quot;
				&quot;Und gibt den neuen Inhalt aus\n&quot;
				&quot;Bitte per &lt;prog&gt; &lt;datei&gt; &lt;wort&gt; starten&quot; &lt;&lt; endl;
		return 0;
	}
	string data;
	string find_s(argv[2]); // der string den wir suchen

	ifstream file(argv[1]); // öffnet die datei aus dem ersten argument

	file.unsetf(ios::skipws); // stellt das überspringen von whitespace ab

	data.assign( // zuweisung von daten an den data string
             istream_iterator&lt;char&gt;(file), //anfang der datei
             istream_iterator&lt;char&gt;()); // ende der datei

	file.close();

	int pos=0;

        // solange wie der zu entfernende string vorhanden: 
        //     entferne ihn einmal
	while( (pos=data.find(find_s, pos))!=string::npos) 
		data.erase(pos, find_s.length());

	cout &lt;&lt; data;
	return 0;
}
</code></pre>
<p>@(D)Evil: thx für den hinweis - solche kleinigkeiten vergisst man gerne wenn man nicht mehr so oft mit c++ arbeitet</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1287104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1287104</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Thu, 17 May 2007 22:29:15 GMT</pubDate></item></channel></rss>