<?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[zahlen aus std::string in std::vector]]></title><description><![CDATA[<p>hola</p>
<p>ich hab in einem std::string einige int-werte die durch ein leerzeichen getrennt sind. nun sachte ich mir das ich dir zahlen mittels std::cin in meinen<br />
std::vector&lt;int&gt; reinschieben kann. wollte das mit rdbuf machen, funktioniert leider nicht.<br />
wie macht man das am besten ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149454/zahlen-aus-std-string-in-std-vector</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 07:40:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149454.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Jun 2006 09:33:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 09:33:40 GMT]]></title><description><![CDATA[<p>hola</p>
<p>ich hab in einem std::string einige int-werte die durch ein leerzeichen getrennt sind. nun sachte ich mir das ich dir zahlen mittels std::cin in meinen<br />
std::vector&lt;int&gt; reinschieben kann. wollte das mit rdbuf machen, funktioniert leider nicht.<br />
wie macht man das am besten ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072289</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Tue, 06 Jun 2006 09:33:40 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 09:34:45 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>such hier im Forum nach <em>*explode*</em>.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072290</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 06 Jun 2006 09:34:45 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 09:53:26 GMT]]></title><description><![CDATA[<p>hoi akari</p>
<p>wenn ich es richtig verstanden habe dann zerlegt mir explode nen string in einzelne. das wollte ich ansich nicht haben.<br />
mir geht es nur darum das ich die eingabe von z.b. std::cin so umbiegen kann, das er nicht die eingabe von der tastatur ueber nimmt sondern von einem std::string.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072304</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Tue, 06 Jun 2006 09:53:26 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 10:06:08 GMT]]></title><description><![CDATA[<p>Dafür nimmst Du einen std::stringstream, schreibst den String da rein (wie in cout) und holst die Zahlen wieder raus (wie aus cin) <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/1072315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072315</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 06 Jun 2006 10:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 10:07:27 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p><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="😕"
    /><br />
Und wohin willst du das Umbiegen?</p>
<p>So wie ich das versteh hast du einen string mit durch Leerzeichen getrennten Zahlenwerte. Und du willst das auftrennen und die einzelnen Werte in einen Integer-vector.</p>
<p>Und genau dazu nimmst du explode, und brauchst nur noch ein lexical_cast bzw. ein stringstream um die Teilstrings in Integers umzuwandeln.</p>
<p>Eventuell läßt sich das ganze auch ganz auf einen stringstream reduzieren.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072317</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 06 Jun 2006 10:07:27 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 10:11:44 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::stringstream ss(&quot;123 456 789&quot;);
int i;
ss &gt;&gt; i;
v.push_back(i);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1072320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072320</guid><dc:creator><![CDATA[ss]]></dc:creator><pubDate>Tue, 06 Jun 2006 10:11:44 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 10:16:46 GMT]]></title><description><![CDATA[<p>re</p>
<p>naja mit stringstreams wuerde es ja auch funktionieren.<br />
aber ich find da keine funktion wie ich dem stringstream nen string zuweissen kann, den er als buffer ansieht.<br />
sonst muesste ich erst den string in den stringstream reinschieben, was aber recht unnoetiger zeitaufwand ist.<br />
oder ich muesste nen haufen code umschreiben, das ein stringstream anstatt eines strings verwendet wird. worauf ich jetz auch nicht viel lust habe.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072331</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Tue, 06 Jun 2006 10:16:46 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 10:24:11 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>du hast genug Vorschläge bekommen. Wenn dir keiner passt können wir dir auch nicht helfen.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072338</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 06 Jun 2006 10:24:11 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 11:36:30 GMT]]></title><description><![CDATA[<p>Meep Meep schrieb:</p>
<blockquote>
<p>re</p>
<p>naja mit stringstreams wuerde es ja auch funktionieren.<br />
aber ich find da keine funktion wie ich dem stringstream nen string zuweissen kann, den er als buffer ansieht.</p>
</blockquote>
<p>Klar gibt es so eine Funktion, die nennt sich clevererweise <a href="http://cppreference.com/cppsstream/str.html" rel="nofollow">str(s)</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072400</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 11:38:31 GMT]]></title><description><![CDATA[<blockquote>
<p>Second, str() can be used to <strong>copy</strong>a string into the stream</p>
</blockquote>
<p>Ich glaube es geht ihm darum die Kopie zu verhindern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072402</guid><dc:creator><![CDATA[........]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:38:31 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 11:47:17 GMT]]></title><description><![CDATA[<p>hola leute</p>
<p>bin jetzt nen kleinen schritt weiter gekommen.<br />
hab mal von std::streambuf ne klasse abgeleitet:</p>
<pre><code class="language-cpp">namespace txl
{
   class StreamBuffer : public std::streambuf
   {
      private:

      public:
         StreamBuffer(std::string &amp;str)
         {
            this-&gt;pubsetbuf(str.begin(), str.length());
         }
   };
}
</code></pre>
<p>und hab als kleines testprogramm folgendes genommen:</p>
<pre><code class="language-cpp">int main(int argc, char* argv[])
{
   std::string str = &quot;0 1 2 3 4 5 6 7 8 9 10 11 12 13 \n 14 15&quot;;
   std::vector&lt;int&gt; vec;

   txl::StreamBuffer *buf = new txl::StreamBuffer(str);
   std::streambuf *old_buf = std::cin.rdbuf();
   std::cin.rdbuf(buf);
   int x = 0;
   while(std::cin &gt;&gt; x)
      vec.push_back(x);
   std::cin.rdbuf(old_buf);

   for(unsigned int i = 0;i &lt; vec.size();++i)
   {
      std::cout &lt;&lt; vec[i] &lt;&lt; std::endl;
   }

   std::cout &lt;&lt; &quot;originalstring: &quot; &lt;&lt; str &lt;&lt; std::endl;
   return 0;
}

kompilieren tut es ohne meldungen. jedoch wird dann nur der originalstring ausgegeben. std::cin liefert schon beim ersten einlesen in x failbit.
was hab ich da falsch gemacht ?

Meep Meep
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1072412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072412</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:47:17 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 11:52:27 GMT]]></title><description><![CDATA[<p>Einen Stream-Buffer zusammenzubauen ist imho Overkill für deine Zwecke (und selbst wenn, dann benötigt dein Buffer noch einige Hilfsfunktionen). Nimm lieber den vorgegebenen std::ostringstream, der macht genau das, was du benötigst.</p>
<p>(und noch einmal: Mit der Methode str() kannst du dem Stream einen neuen Eingabestring übergeben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072417</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072417</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:52:27 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 11:59:56 GMT]]></title><description><![CDATA[<p>Sag mal, also ehrlich, das Einfügen des Strings in nen stringstream um ihn danach wie cin zu benutzen ist Dir zu aufwändig, aber dasselbe von hinten durch die Brust ins Auge durch eine neue Klasse und dreimal Zeigergehampel zu lösen passt Dir dann?!</p>
<p><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/1072425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072425</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:59:56 GMT</pubDate></item><item><title><![CDATA[Reply to zahlen aus std::string in std::vector on Tue, 06 Jun 2006 12:11:23 GMT]]></title><description><![CDATA[<p>wenn ich meinem StreamBuffer den string uebergebe, wird er dann ueber pubsetbuf n den stream kopiert ? oder nur ne referenz von wo std::cin da lesen kann ?<br />
die strings haben ne groesse von 1-2 MB. und jedes mal zuerst den string in nen stream kopieren, is unnoetiger zeitaufwand. dachte das ich es mir so ersparen kann.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072436</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Tue, 06 Jun 2006 12:11:23 GMT</pubDate></item></channel></rss>