<?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[Streams benutzen(2 fragen)]]></title><description><![CDATA[<p>hi</p>
<p>kann mir jemand bitte sagen, wie ich:</p>
<p><strong>1 &gt;&gt;</strong> In einer Datei ein bestimmten String bzw. ein bestimmtes Wort finden kann? (also zbsp. ich hab ne test.txt Datei und dort hab ich folgendes stehen:</p>
<blockquote>
<p>Hallo &quot;HAHA&quot;<br />
test test4<br />
passwort: 31</p>
</blockquote>
<p>und ich prüfen will ob nach &quot;Hallo&quot; das Wort inkl. <strong>&quot; &quot;</strong> =&gt; &quot;HAHA&quot; steht oder ein anderes Wort. Ist es ein anderes Wort, so wird ein Text &quot;nicht haha&quot; ausgegeben, sonst &quot;ok&quot;.)<br />
__________________________________________________________________________<br />
<strong>2 &gt;&gt;</strong> In eine Datei vor oder nach einen String ein bestimmtes Wort einzufügen.</p>
<p>Wäre nett wenn mir jemand helfen könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Mit bestem dank im voraus,<br />
_asm <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/192025/streams-benutzen-2-fragen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 07:59:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/192025.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 09 Sep 2007 17:55:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 17:55:12 GMT]]></title><description><![CDATA[<p>hi</p>
<p>kann mir jemand bitte sagen, wie ich:</p>
<p><strong>1 &gt;&gt;</strong> In einer Datei ein bestimmten String bzw. ein bestimmtes Wort finden kann? (also zbsp. ich hab ne test.txt Datei und dort hab ich folgendes stehen:</p>
<blockquote>
<p>Hallo &quot;HAHA&quot;<br />
test test4<br />
passwort: 31</p>
</blockquote>
<p>und ich prüfen will ob nach &quot;Hallo&quot; das Wort inkl. <strong>&quot; &quot;</strong> =&gt; &quot;HAHA&quot; steht oder ein anderes Wort. Ist es ein anderes Wort, so wird ein Text &quot;nicht haha&quot; ausgegeben, sonst &quot;ok&quot;.)<br />
__________________________________________________________________________<br />
<strong>2 &gt;&gt;</strong> In eine Datei vor oder nach einen String ein bestimmtes Wort einzufügen.</p>
<p>Wäre nett wenn mir jemand helfen könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Mit bestem dank im voraus,<br />
_asm <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/1362083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362083</guid><dc:creator><![CDATA[_asm]]></dc:creator><pubDate>Sun, 09 Sep 2007 17:55:12 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 18:02:46 GMT]]></title><description><![CDATA[<p>1. In String einlesen, und nach den Worten durchsuchen. Oder falls es Zeilenweise praktischer wäre, den Stream per std::getline() in einen vector einlesen und jede einzelne zeile durchgehen.</p>
<p>2. Im Prinzip das gleiche; Datei in einen String lesen, ersetzen/einfügen und wieder zurückschreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362093</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sun, 09 Sep 2007 18:02:46 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 18:28:58 GMT]]></title><description><![CDATA[<p>sorry, aber ich weiß nicht wie ich das realisieren soll.<br />
Folgendes hab ich schon probiert:</p>
<pre><code class="language-cpp">void find(std::string file, std::string name)
{
	std::ifstream output;
	output.open(file.c_str());
	for(std::string::iterator x = name[x]; x != name; ++x)
	{
		if(x == name)
		{
			std::cout &lt;&lt; &quot;GEFUNDEN&quot;;
		} else {
			std::cout &lt;&lt; &quot;Suche ..&quot; &lt;&lt; std::endl;
		}
	}
}
</code></pre>
<p>funktioniert aber nicht, da compilererrors.</p>
<p>kannst du mir einmal zeigen, wie es geht?<br />
ich weiß nichtmal was du mit</p>
<blockquote>
<p>In String einlesen, und nach den Worten durchsuchen</p>
</blockquote>
<p>meinst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362112</guid><dc:creator><![CDATA[_asm]]></dc:creator><pubDate>Sun, 09 Sep 2007 18:28:58 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 18:51:08 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void find(std::string file, std::string name)
{
	std::ifstream output;
	output.open(file.c_str());
	std::vector&lt;std::string&gt; source;
	for(std::string::size_type x = 0; x != source.size(); ++x)
	{
		source.push_back(output);
	}
}
</code></pre>
<p>scheint auch nicht zu klappen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Kannst du mir wenigstens Tipps geben? oder den code?</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362135</guid><dc:creator><![CDATA[_Asm]]></dc:creator><pubDate>Sun, 09 Sep 2007 18:51:08 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 20:07:41 GMT]]></title><description><![CDATA[<p>push <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362201</guid><dc:creator><![CDATA[_Asm]]></dc:creator><pubDate>Sun, 09 Sep 2007 20:07:41 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 20:21:18 GMT]]></title><description><![CDATA[<p>Eigentlich sollte man nach so einem dreisten gepushe garnichts mehr sagen... aber nagut:</p>
<pre><code class="language-cpp">void find(std::string file, std::string name) 
{ 
    std::fstream output; 
    output.open(file.c_str()); 
    std::vector&lt;std::string&gt; source; 
    while(output.good()) 
    { 
        std::string line;
        std::getline(output, line);
        if(line.find(name) != std::string::npos)
        {
            std::cout &lt;&lt; &quot;gefunden!&quot; &lt;&lt; std::endl;
            break;
        }
    } 
}
</code></pre>
<p>So oder so ähnlich müsste es passen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362207</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sun, 09 Sep 2007 20:21:18 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Sun, 09 Sep 2007 20:39:16 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;string&gt;
// ...
bool find(const std::string&amp; filename, const std::string&amp; data)
{
    std::ifstream input(filename.c_str()); // Datei öffnen
    if (!input) return false;
    std::string line; // Soll die Zeile reingelesen werden
    while (std::getline(input, line)) // Zeile aus input(Datei) in line(String) lesen ...
        if (line.find(data) != std::string::npos) // Wenn data(String) vorhanden
            return true; // erfolgreich
    return false; // nicht da ...
}
</code></pre>
<p>...</p>
<p>Für 1:</p>
<pre><code class="language-cpp">std::string const&amp; get_value(const std::string&amp; filename, const std::string&amp; var)
{
    std::ifstream input(filename.c_str());
    if (!input) throw std::invalid_argument(&quot;could not open file&quot;);
    std::string line;
    while (std::getline(input, line))
    {
        std::size_t pos = line.find(var);
        pos = line.find_first_not_of(' ', pos);
        if (pos != std::string::npos)
            return line.substr(pos);
    }
    throw std::runtime_error(&quot;var not set&quot;);
}
</code></pre>
<pre><code class="language-cpp">int main()
{
    try
    {
        std::cout &lt;&lt; get_value(&quot;test.txt&quot;, &quot;Hallo&quot;) &lt;&lt; std::endl;
    } catch(std::exception&amp; ex)
    {
        std::cerr &lt;&lt; &quot;FEHLER: &quot; &lt;&lt; ex.what() &lt;&lt; std::endl;
    }
};
</code></pre>
<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362215</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sun, 09 Sep 2007 20:39:16 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Mon, 10 Sep 2007 13:04:06 GMT]]></title><description><![CDATA[<p>'getline': Ist kein Element von 'std'<br />
und der bezeichner wurde nicht gefunden:</p>
<pre><code class="language-cpp">bool find(const std::string&amp; file, const std::string &amp;data)
{
	std::fstream read;
	read.open(file.c_str());
	if(!read)
	{
		std::cerr &lt;&lt; &quot;File couldn't be found.&quot; &lt;&lt; std::endl;
		return false;
	}
	std::string line;
	while(std::getline(read, line))
	{
		if(line.find(data) != std::string::npos)
		{
			std::cout &lt;&lt; &quot;Gefunden&quot; &lt;&lt; std::endl;
			return true;
		}
	}
	return false;
}
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362569</guid><dc:creator><![CDATA[_asm]]></dc:creator><pubDate>Mon, 10 Sep 2007 13:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Mon, 10 Sep 2007 13:14:09 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1362586</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362586</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Mon, 10 Sep 2007 13:14:09 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Mon, 10 Sep 2007 14:43:30 GMT]]></title><description><![CDATA[<p>THX HAT GEKLAPPT!</p>
<p>nur noch letzte frage: wie kann ich noch im nachhinein einen text an eine bestimmte stelle schreiben?<br />
habs so versucht:</p>
<pre><code class="language-cpp">bool find(const std::string&amp; file, const std::string &amp;data)
{
	std::fstream read;
	read.open(file.c_str());
	if(!read)
	{
		std::cerr &lt;&lt; &quot;File couldn't be found.&quot; &lt;&lt; std::endl;
		return false;
	}
	std::string line;
	while(std::getline(read, line))
	{
		if(line.find(data) != std::string::npos)
		{
			std::cout &lt;&lt; line.find(data) &lt;&lt; std::endl;
			std::cout &lt;&lt; &quot;Gefunden, edit&quot; &lt;&lt; std::endl;
			read &lt;&lt; &quot;HALLO&quot;; // einfach durch read
			return true;
		}
	}
	return false;
}
</code></pre>
<p>erscheint dann aber nicht in der file <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362640</guid><dc:creator><![CDATA[_asm]]></dc:creator><pubDate>Mon, 10 Sep 2007 14:43:30 GMT</pubDate></item><item><title><![CDATA[Reply to Streams benutzen(2 fragen) on Mon, 10 Sep 2007 15:03:30 GMT]]></title><description><![CDATA[<p>Tja ... also du solltest den Code den ich dir gegeben habe nicht verschlimmbessern ...</p>
<p>Zu deinem Problem: read ist weder als std::ios::in noch als std::ios::out geöffnet ... also solltest de vllt mal setzen -.-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362654</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Mon, 10 Sep 2007 15:03:30 GMT</pubDate></item></channel></rss>