<?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[Übergabe eines Vectors]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>Diesemal würde ich gerne wissen wie ich einen Vector in einem parameter übergeben kann. Als Beispiel:</p>
<pre><code>Config::Config(const std::string&amp; file, std::vector&lt;std::string&gt; content)
{
    std::ofstream properties;
    properties.open(file);
    properties &lt;&lt; content;
    properties.close();
}
</code></pre>
<pre><code>new Config(blabla, &quot;Test1&quot;,
                   &quot;Test2&quot;
)
</code></pre>
<p>Doch dieser Code funktioniert nicht. So ich weiss das dies für manche eine dumme frage ist würde mir jedoch sehr helfen.</p>
<p>MFG Jonas</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/331456/übergabe-eines-vectors</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 15:51:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331456.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Mar 2015 21:05:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Übergabe eines Vectors on Sun, 01 Mar 2015 21:05:42 GMT]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>Diesemal würde ich gerne wissen wie ich einen Vector in einem parameter übergeben kann. Als Beispiel:</p>
<pre><code>Config::Config(const std::string&amp; file, std::vector&lt;std::string&gt; content)
{
    std::ofstream properties;
    properties.open(file);
    properties &lt;&lt; content;
    properties.close();
}
</code></pre>
<pre><code>new Config(blabla, &quot;Test1&quot;,
                   &quot;Test2&quot;
)
</code></pre>
<p>Doch dieser Code funktioniert nicht. So ich weiss das dies für manche eine dumme frage ist würde mir jedoch sehr helfen.</p>
<p>MFG Jonas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444866</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444866</guid><dc:creator><![CDATA[Andreas W.]]></dc:creator><pubDate>Sun, 01 Mar 2015 21:05:42 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Sun, 01 Mar 2015 21:07:42 GMT]]></title><description><![CDATA[<p>Mit geschweiften Klammern:</p>
<pre><code class="language-cpp">Config conf(blabla, {&quot;Test1&quot;, &quot;Test2&quot;});
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2444867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444867</guid><dc:creator><![CDATA[newdelete]]></dc:creator><pubDate>Sun, 01 Mar 2015 21:07:42 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Mon, 02 Mar 2015 07:34:31 GMT]]></title><description><![CDATA[<p>Erkläre lieber mal, wieso du new und .close() verwendest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444885</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 02 Mar 2015 07:34:31 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Mon, 02 Mar 2015 08:37:01 GMT]]></title><description><![CDATA[<p>Noch besser wäre die Übergabe als const Ref, dann sparst du das Kopieren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444891</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Mon, 02 Mar 2015 08:37:01 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Mon, 02 Mar 2015 09:40:02 GMT]]></title><description><![CDATA[<p>Du kannst auch auf das explizite Öffnen und Schließen der Datei verzichten, da das der Konstruktor und Destruktor des ofstream macht. Optimaler Weise sähe das dann so aus:</p>
<pre><code>Config::Config(const std::string&amp; file, const std::vector&lt;std::string&gt;&amp; content) 
{ 
    std::ofstream properties(file); 
    properties &lt;&lt; content;  
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2444896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444896</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Mon, 02 Mar 2015 09:40:02 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Mon, 02 Mar 2015 16:33:23 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Optimaler Weise sähe das dann so aus:</p>
<pre><code>Config::Config(const std::string&amp; file, const std::vector&lt;std::string&gt;&amp; content) 
{ 
    std::ofstream properties(file); 
    properties &lt;&lt; content;  
}
</code></pre>
</blockquote>
<p>Ich bin nicht der Meinung, dass das optimal wäre, schon nur deshalb, weil sich ein Vektor nicht direkt ausgeben lässt.</p>
<p>Vorschlag:</p>
<pre><code>template &lt;typename Range&gt;
Config::Config(const char* path, const Range&amp; content) 
{ 
    std::ofstream propfile(file);
    std::copy(std::ostream_iterator&lt;typename Range::value_type&gt;(propfile, &quot;\n&quot;), {}, content);
                                 // ^-------------------------
                                 // War das ein Oversight, oder wieso
                                 // gibt es in C++14 nicht keine
                                 // ostream_iterator&lt;void&gt;-Spezialisierung?
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2444929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444929</guid><dc:creator><![CDATA[c++14-oversight?]]></dc:creator><pubDate>Mon, 02 Mar 2015 16:33:23 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Mon, 02 Mar 2015 19:15:39 GMT]]></title><description><![CDATA[<p>Ich behaupte mal dass die Parameter für dein <code>std::copy</code> komplett falsch sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444969</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 02 Mar 2015 19:15:39 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe eines Vectors on Tue, 03 Mar 2015 08:12:04 GMT]]></title><description><![CDATA[<p>c++14-oversight? schrieb:</p>
<blockquote>
<p>Ich bin nicht der Meinung, dass das optimal wäre, schon nur deshalb, weil sich ein Vektor nicht direkt ausgeben lässt.</p>
</blockquote>
<p>Darum ging es nicht. Das die Ausgabe von Andreas W. nicht funktioniert ist eine andere Baustelle. Deine Lösung funktioniert zudem auch nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2445014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2445014</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Tue, 03 Mar 2015 08:12:04 GMT</pubDate></item></channel></rss>