<?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[Wie mehrere Folgen von Zahlen einlesen?]]></title><description><![CDATA[<p>Guten Abend</p>
<p>Ich bin gerade etwas verwirrt mit dem Input über std::cin in C++. Ich habe z.B. folgenden zeilenweisen Keyboard-Input:</p>
<p>3<br />
1 3 3 -234 2 3<br />
1 3 3 -21<br />
- 1 3 3 393 2 1 3 -3</p>
<p>Die 3 gibt die Anzahl der Folgen an. Die Länge einer einzigen Zahlenfolge ist unbekannt. Ich möchte deshalb jede Folge in einem std::vector&lt;int&gt; speichern können.</p>
<p>Wie mache ich das am besten? Ich habe schon ein par Dinge ausprobiert aber die haben irgendwie nicht geklappt <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=":-/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/283224/wie-mehrere-folgen-von-zahlen-einlesen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 17:39:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/283224.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Mar 2011 20:26:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Mon, 07 Mar 2011 20:27:03 GMT]]></title><description><![CDATA[<p>Guten Abend</p>
<p>Ich bin gerade etwas verwirrt mit dem Input über std::cin in C++. Ich habe z.B. folgenden zeilenweisen Keyboard-Input:</p>
<p>3<br />
1 3 3 -234 2 3<br />
1 3 3 -21<br />
- 1 3 3 393 2 1 3 -3</p>
<p>Die 3 gibt die Anzahl der Folgen an. Die Länge einer einzigen Zahlenfolge ist unbekannt. Ich möchte deshalb jede Folge in einem std::vector&lt;int&gt; speichern können.</p>
<p>Wie mache ich das am besten? Ich habe schon ein par Dinge ausprobiert aber die haben irgendwie nicht geklappt <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=":-/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2030988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2030988</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Mon, 07 Mar 2011 20:27:03 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Mon, 07 Mar 2011 20:32:31 GMT]]></title><description><![CDATA[<p>Generell: jede Zeile einzeln einlesen und sie dann getrennt parsen. Die Zeilen bekommst du mit <code>getline</code> , danach hilft dir sicherlich ein <code>istringstream</code> . Die zwei Streams sind zwar performancetechnisch eher suboptimal (im Vergleich zu Parserlösungen), aber wohl erstmal am einfachsten zu coden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2030991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2030991</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Mon, 07 Mar 2011 20:32:31 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Mon, 07 Mar 2011 21:10:49 GMT]]></title><description><![CDATA[<p>Für getline müsste ich dann allerdings ein char-Array verwenden, nicht? Das wäre schon nicht so toll.</p>
<p>Ich schau mal was ich hinbekomme.</p>
<p>Danke für die Antwort.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031002</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031002</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Mon, 07 Mar 2011 21:10:49 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Mon, 07 Mar 2011 21:19:15 GMT]]></title><description><![CDATA[<p>icarus2 schrieb:</p>
<blockquote>
<p>Für getline müsste ich dann allerdings ein char-Array verwenden, nicht? Das wäre schon nicht so toll.</p>
<p>Ich schau mal was ich hinbekomme.</p>
<p>Danke für die Antwort.</p>
</blockquote>
<p>Nein, es gibt eine globale Version für <code>std::string</code> : <a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">getline()</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031007</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031007</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Mon, 07 Mar 2011 21:19:15 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Mon, 07 Mar 2011 21:40:10 GMT]]></title><description><![CDATA[<p>mit dem 'is_endl' <a href="http://www.c-plusplus.net/forum/p1940874#1940874" rel="nofollow">aus diesem Thread</a> geht das recht elegant und ohne lästiges getline</p>
<pre><code class="language-cpp">#include &quot;is_endl.h&quot; // s. &lt;http://www.c-plusplus.net/forum/p1940874#1940874&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

int main()
{
    using namespace std;
    int n;
    if( cin &gt;&gt; n &gt;&gt; ws )
    {
        vector&lt; vector&lt; int &gt; &gt; alle(n);
        for( vector&lt; vector&lt; int &gt; &gt;::iterator i = alle.begin(); i != alle.end(); ++i )
            for( int z; !is_endl( cin ) &amp;&amp; cin &gt;&gt; z ; )
                i-&gt;push_back( z );
        cout &lt;&lt; &quot;fertig&quot; &lt;&lt; endl;
    }
    return 0;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031017</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031017</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 07 Mar 2011 21:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Tue, 08 Mar 2011 16:17:17 GMT]]></title><description><![CDATA[<p>Ich habs heute in kurzer Zeit hinbekommen. War wohl nicht mein Tag gestern ^^ Hatte vergessen, dass es eine Überladung von getline mit cin und std::string gibt.</p>
<p>Danke für eure Antworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031395</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Tue, 08 Mar 2011 16:17:17 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Tue, 08 Mar 2011 22:14:56 GMT]]></title><description><![CDATA[<p>Werner Salomon:<br />
Was findest Du an getline lästig außer dass nicht deine patentierte is_endl<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/2122.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--trade_mark"
      title=":trade_mark:"
      alt="™"
    />-Lösung verwendet wird? <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/2031540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031540</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Tue, 08 Mar 2011 22:14:56 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Wed, 09 Mar 2011 07:41:17 GMT]]></title><description><![CDATA[<p>frisst das is_endl eigentlich sowohl linux als auch windows als auch Mac Endlines ('\n' vs. &quot;\r\n&quot; vs. '\r')? Oder erledigt das der Filestream bereits?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031597</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031597</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Wed, 09 Mar 2011 07:41:17 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Wed, 09 Mar 2011 07:59:43 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Was findest Du an getline lästig [...]</p>
</blockquote>
<p>Die Aufgabe war 'Zahlen zu lesen'</p>
<p>icarus2 schrieb:</p>
<blockquote>
<p>3<br />
1 3 3 -234 2 3<br />
1 3 3 -21<br />
- 1 3 3 393 2 1 3 -3</p>
<p>[...] Zahlenfolge [...] in einem std::vector&lt;<strong>int</strong>&gt; speichern [...]</p>
</blockquote>
<p>'getline' liest aber keine Zahlen.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031605</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 09 Mar 2011 07:59:43 GMT</pubDate></item><item><title><![CDATA[Reply to Wie mehrere Folgen von Zahlen einlesen? on Wed, 09 Mar 2011 08:05:58 GMT]]></title><description><![CDATA[<p>padreigh schrieb:</p>
<blockquote>
<p>frisst das is_endl eigentlich sowohl linux als auch windows als auch Mac Endlines ('\n' vs. &quot;\r\n&quot; vs. '\r')? Oder erledigt das der Filestream bereits?</p>
</blockquote>
<p>wenn alles 'gemäß Standard' zugeht, sollte das die <a href="http://www.cplusplus.com/reference/std/locale/codecvt/" rel="nofollow">codecvt-Facette</a> im streambuf erledigen. Vorausgesetzt, Du öffnest die Datei nicht im binary-Mode.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2031611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2031611</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 09 Mar 2011 08:05:58 GMT</pubDate></item></channel></rss>