<?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[Filestream]]></title><description><![CDATA[<pre><code>int main()
{
	std::ifstream file(&quot;Account.txt&quot;);

	std::map&lt;std::string, std::string&gt; accounts;

	std::string line;
	std::string id, pw;

	while (std::getline(file, line))
	{
		std::stringstream buffer;
		buffer.str(line);
		buffer &gt;&gt; id;
		buffer &gt;&gt; pw;
		accounts.insert({ id, pw });
	}

	for (auto account : accounts)
	{
		std::cout &lt;&lt; account.first &lt;&lt; &quot; &quot; &lt;&lt; account.second &lt;&lt; std::endl;
	}

	file.close();

	system(&quot;pause&quot;);

	return 0;
}
</code></pre>
<p>Wie könnte man den Code verbessern?<br />
Ich versuche aus einer Informationen herauszulesen und diese dann in einer Map zu speichern anschließend gebe ich die Informationen aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/334113/filestream</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 00:59:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/334113.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 Aug 2015 11:48:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Filestream on Sun, 23 Aug 2015 11:48:46 GMT]]></title><description><![CDATA[<pre><code>int main()
{
	std::ifstream file(&quot;Account.txt&quot;);

	std::map&lt;std::string, std::string&gt; accounts;

	std::string line;
	std::string id, pw;

	while (std::getline(file, line))
	{
		std::stringstream buffer;
		buffer.str(line);
		buffer &gt;&gt; id;
		buffer &gt;&gt; pw;
		accounts.insert({ id, pw });
	}

	for (auto account : accounts)
	{
		std::cout &lt;&lt; account.first &lt;&lt; &quot; &quot; &lt;&lt; account.second &lt;&lt; std::endl;
	}

	file.close();

	system(&quot;pause&quot;);

	return 0;
}
</code></pre>
<p>Wie könnte man den Code verbessern?<br />
Ich versuche aus einer Informationen herauszulesen und diese dann in einer Map zu speichern anschließend gebe ich die Informationen aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465192</guid><dc:creator><![CDATA[Newbie2222]]></dc:creator><pubDate>Sun, 23 Aug 2015 11:48:46 GMT</pubDate></item><item><title><![CDATA[Reply to Filestream on Sun, 23 Aug 2015 12:41:09 GMT]]></title><description><![CDATA[<p>Wieso liest du eine Zeile vom Stream, packste die in einen anderen Stream und liest erst daraus dann die Daten, die du haben willst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465194</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 23 Aug 2015 12:41:09 GMT</pubDate></item><item><title><![CDATA[Reply to Filestream on Sun, 23 Aug 2015 12:43:59 GMT]]></title><description><![CDATA[<p>Du kannst den stringstream auch weglassen:</p>
<pre><code>while (file &gt;&gt; id &gt;&gt; pw)
    accounts.insert({ id, pw });
</code></pre>
<p>Nachteil: Könnte schiefgehen wenn es pro Zeile mehr als zwei Strings gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465195</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Sun, 23 Aug 2015 12:43:59 GMT</pubDate></item><item><title><![CDATA[Reply to Filestream on Sun, 23 Aug 2015 12:54:02 GMT]]></title><description><![CDATA[<p>So dürfte es identisch sein:</p>
<pre><code>while (file &gt;&gt; id &gt;&gt; pw)
{
    accounts.insert({ id, pw });
    file.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2465196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465196</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Sun, 23 Aug 2015 12:54:02 GMT</pubDate></item><item><title><![CDATA[Reply to Filestream on Sun, 23 Aug 2015 13:00:53 GMT]]></title><description><![CDATA[<p>sebi707 schrieb:</p>
<blockquote>
<p>So dürfte es identisch sein:</p>
<pre><code>while (file &gt;&gt; id &gt;&gt; pw)
{
    accounts.insert({ id, pw });
    file.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
}
</code></pre>
</blockquote>
<p>Ists nicht, Bsp. &quot;a\nb&quot;.</p>
<p>Die Variante des TE ist aber auch nicht ideal, &quot;a b c&quot; wird als &quot;a&quot;+&quot;b&quot; geparsed und &quot;a&quot; als &quot;a&quot;+&quot;&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465198</guid><dc:creator><![CDATA[dürtiger]]></dc:creator><pubDate>Sun, 23 Aug 2015 13:00:53 GMT</pubDate></item></channel></rss>