<?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[list in vector umwandeln und umgekehrt]]></title><description><![CDATA[<p>Hallo,<br />
ich habe folgendes Problem:<br />
ich will die C++ STL verwenden und bei einem vector die methoden einer liste verwenden. Kann ich eine Liste irgendwie in einen vector umwandeln und umgekehrt?<br />
Und wie mache ich das mit den includes? &lt;list&gt; und &lt;vector&gt; schließen sich ja aus.</p>
<pre><code>#include &lt;list&gt;
#include &lt;vector&gt;
using namespace std;

vector&lt;int&gt; v;          //hat die Methoden eines vectors und nicht einer liste
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/140930/list-in-vector-umwandeln-und-umgekehrt</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 11:05:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/140930.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Mar 2006 10:27:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to list in vector umwandeln und umgekehrt on Sat, 18 Mar 2006 10:27:33 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe folgendes Problem:<br />
ich will die C++ STL verwenden und bei einem vector die methoden einer liste verwenden. Kann ich eine Liste irgendwie in einen vector umwandeln und umgekehrt?<br />
Und wie mache ich das mit den includes? &lt;list&gt; und &lt;vector&gt; schließen sich ja aus.</p>
<pre><code>#include &lt;list&gt;
#include &lt;vector&gt;
using namespace std;

vector&lt;int&gt; v;          //hat die Methoden eines vectors und nicht einer liste
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1018866</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1018866</guid><dc:creator><![CDATA[Klausi]]></dc:creator><pubDate>Sat, 18 Mar 2006 10:27:33 GMT</pubDate></item><item><title><![CDATA[Reply to list in vector umwandeln und umgekehrt on Sat, 18 Mar 2006 10:41:19 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<blockquote>
<p>Kann ich eine Liste irgendwie in einen vector umwandeln und umgekehrt?</p>
</blockquote>
<p>Jup, denn sowohl std::list als auch std::vector besitzen einen Ctor, über den du die Liste/den Vektor mit den Elementen initialisierst, die sich zwischen den angegebenen Iteratoren befinden. (Siehe eventuell auch die besagten Ctoren von std::list und std::vector!)</p>
<p>Bsp: std::list to std::vector</p>
<pre><code class="language-cpp">#include &lt;list&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
using namespac std;

int main()
{
    list&lt;int&gt; l;
    l.push_back(9);
    l.push_back(18);
    l.push_back(27);
    // ..
    vector&lt;int&gt; v(l.begin(), l.end()); // alle Elemente von List in den Vektor...

    //testausgabe:
    copy(v.begin(), v.end(), ostream_iterator&lt;int&gt;(cout, &quot;|&quot;));
    cout &lt;&lt; endl;
}
</code></pre>
<p>Von vector nach list gehts analog zu dem Beispiel.</p>
<p>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1018871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1018871</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Sat, 18 Mar 2006 10:41:19 GMT</pubDate></item><item><title><![CDATA[Reply to list in vector umwandeln und umgekehrt on Sat, 18 Mar 2006 10:41:31 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>es geht aber auch mit std::copy, wenn man nicht alles kopieren will:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;

//...

std::copy(v.begin(),v.end(),l.begin());
</code></pre>
<p>Statt begin() oder end() setzt man dann eben was anderes ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1018874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1018874</guid><dc:creator><![CDATA[picocat]]></dc:creator><pubDate>Sat, 18 Mar 2006 10:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to list in vector umwandeln und umgekehrt on Sat, 18 Mar 2006 17:13:20 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/1086">@Lars</a> Hupel:<br />
Das was du da machst ist brandgefährlich!<br />
Wer sagt dir das die Liste l ausreichend Speicher bereitstellt?<br />
copy inkrementiert den Iterator brutal weiter,ob der jetzt noch auf gültigen Speicher &quot;zeigt&quot; oder auch nicht.<br />
Für diesen Fall gibt es insert Iteratoren.</p>
<p>MfG Spacelord</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019170</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019170</guid><dc:creator><![CDATA[Spacelord]]></dc:creator><pubDate>Sat, 18 Mar 2006 17:13:20 GMT</pubDate></item><item><title><![CDATA[Reply to list in vector umwandeln und umgekehrt on Sat, 18 Mar 2006 17:47:31 GMT]]></title><description><![CDATA[<p>Ah sorry. Mir fällts jetzt auch auf. Ich bin einfach davon ausgegangen, dass dort genügend Speicherplatz vorhanden ist. Aber danke für den Hinweis.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019198</guid><dc:creator><![CDATA[picocat]]></dc:creator><pubDate>Sat, 18 Mar 2006 17:47:31 GMT</pubDate></item><item><title><![CDATA[Reply to list in vector umwandeln und umgekehrt on Sat, 18 Mar 2006 17:56:18 GMT]]></title><description><![CDATA[<p>sicher, dass ne std::deque nicht besser für deine zwecke wäre?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019206</guid><dc:creator><![CDATA[Any]]></dc:creator><pubDate>Sat, 18 Mar 2006 17:56:18 GMT</pubDate></item></channel></rss>