<?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[atof und vector&amp;lt;string&amp;gt;]]></title><description><![CDATA[<p>Das Problem:ich mochte teiweise Elemente kopieren vom vector&lt;string&gt; s in vector&lt;float&gt; x.</p>
<pre><code>for(int i=idx_channel[0];i&lt;idx_channel[1];++i)// idx_channel ist ein vector&lt;int&gt;
	{
		f=atof(s[i].c_str);
		x.push_back(f);		
	}
</code></pre>
<p>FEHLER: error C2440: 'type cast' : cannot convert from 'const char <em>(__thiscall std::basic_string&lt;_Elem,_Traits,_Ax&gt;::</em> )(void) const' to 'char *'<br />
with<br />
[<br />
_Elem=char,<br />
_Traits=std::char_traits&lt;char&gt;,<br />
_Ax=std::allocator&lt;char&gt;<br />
]</p>
<p>Vielleicht gibt es eine Lösungg mit copy, aber ich bin zu neu um richtig mit Iteratoren umzugehen.<br />
Danke für Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/139637/atof-und-vector-lt-string-gt</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 16:20:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/139637.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Mar 2006 10:00:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 10:00:42 GMT]]></title><description><![CDATA[<p>Das Problem:ich mochte teiweise Elemente kopieren vom vector&lt;string&gt; s in vector&lt;float&gt; x.</p>
<pre><code>for(int i=idx_channel[0];i&lt;idx_channel[1];++i)// idx_channel ist ein vector&lt;int&gt;
	{
		f=atof(s[i].c_str);
		x.push_back(f);		
	}
</code></pre>
<p>FEHLER: error C2440: 'type cast' : cannot convert from 'const char <em>(__thiscall std::basic_string&lt;_Elem,_Traits,_Ax&gt;::</em> )(void) const' to 'char *'<br />
with<br />
[<br />
_Elem=char,<br />
_Traits=std::char_traits&lt;char&gt;,<br />
_Ax=std::allocator&lt;char&gt;<br />
]</p>
<p>Vielleicht gibt es eine Lösungg mit copy, aber ich bin zu neu um richtig mit Iteratoren umzugehen.<br />
Danke für Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011324</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011324</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 10:00:42 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 10:02:33 GMT]]></title><description><![CDATA[<p>f=atof(s[i].c_str());</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011326</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011326</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 08 Mar 2006 10:02:33 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 10:04:43 GMT]]></title><description><![CDATA[<p>du hast hinter dem c_str die Funktionsklammern vergessen (im Gegensatz zu Basic oder Pascal kannst du die bei C(++) nicht weglassen, auch wenn keine PArameter notwendig sind):</p>
<pre><code class="language-cpp">f=atof(s[i].c_str());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1011327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011327</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 08 Mar 2006 10:04:43 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 10:24:03 GMT]]></title><description><![CDATA[<p>DANKE!</p>
<p>und wie würde ich von vector&lt;string&gt; s die Elemente 20 bis 50 in vector&lt;float&gt; x kopieren???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011357</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 10:24:03 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 10:31:56 GMT]]></title><description><![CDATA[<p>carmen schrieb:</p>
<blockquote>
<p>und wie würde ich von vector&lt;string&gt; s die Elemente 20 bis 50 in vector&lt;float&gt; x kopieren???</p>
</blockquote>
<p>indem du den richtigen Start- und Endindex für deine Schleife verwendest:</p>
<pre><code class="language-cpp">for(int i=20;i&lt;=50;++i)
{
  float f=atof(s[i].c_str());
  x.push_back(f);
}
</code></pre>
<p>(eventuell kannst du auch &quot;x[i]=f;&quot; verwenden, damit überschreibst du die Elemente 20 bis 50 von x mit den konvertierten Strings)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011369</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 08 Mar 2006 10:31:56 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:01:14 GMT]]></title><description><![CDATA[<p>Ich war nicht klar... SCUZI<br />
Ich reformuliere:</p>
<pre><code>std::copy(vector&lt;string&gt;::iterator s[20].iterator,s[50].iterator,back_inserter(x));
</code></pre>
<p>Wie definiere ich richtig ein Iterator auf s[20], sodass ich copy benutzen kann??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011393</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:01:14 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:12:12 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">s.begin() + n
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1011405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011405</guid><dc:creator><![CDATA[so:]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:12:12 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:23:51 GMT]]></title><description><![CDATA[<p>Sehr schön!</p>
<pre><code>std::copy(s.begin()+idx_channel[0],s.begin()+idx_channel[1],back_inserter(x));
</code></pre>
<p>aber leider fuktioniert nicht</p>
<p>c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(1022): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::allocator&lt;_Ty&gt;::value_type' (or there is no acceptable conversion)<br />
with<br />
[<br />
_Ty=std::string<br />
]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011414</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:23:51 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:28:01 GMT]]></title><description><![CDATA[<p>ist x ein std::vector&lt;float&gt;? Dann wirds wohl nicht gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011418</guid><dc:creator><![CDATA[hmmmmmmm]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:29:31 GMT]]></title><description><![CDATA[<p>Ja, bei einem &quot;blanken&quot; copy lässt du auch die Umwandlung unter den Tisch fallen - du brauchst transform:</p>
<pre><code class="language-cpp">std::transform(s.begin()+idx_channel[0],s.begin()+idx_channel[1],back_inserter(x),atof);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1011421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011421</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:29:31 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:36:50 GMT]]></title><description><![CDATA[<p>Geht auch nicht!</p>
<p>c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(388): error C2664: 'double (const char *)' : cannot convert parameter 1 from 'std::allocator&lt;_Ty&gt;::value_type' to 'const char *'<br />
with<br />
[<br />
_Ty=std::string<br />
]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011428</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:36:50 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:38:18 GMT]]></title><description><![CDATA[<p>Warum benutzt du nicht die for-Schleife?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011431</guid><dc:creator><![CDATA[for]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:38:18 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:41:42 GMT]]></title><description><![CDATA[<p>Ich wollte nur elleganter schreiben...und die Algorithmen benutzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011434</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:41:42 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 11:48:02 GMT]]></title><description><![CDATA[<p>Dann könntest du statt atof eine der C++-typischeren Umwandlungsmethoden (z.B. über stringstream's oder per boost::lexical_cast) verwenden - schau mal in die FAQ, was es da gibt.</p>
<p>oder du schreibst dir eine Hilfsfunktion:</p>
<pre><code class="language-cpp">inline float stof(const string&amp; in)
{ return atof(in.c_str()); }

transform(s.begin(),s.end(),back_inserter(x),stof);
</code></pre>
<p>PS: eine weitere Alternative wäre es, den richtigen Funktor für transform() aus compose, mem_fun etc zusammenzubauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011446</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 08 Mar 2006 11:48:02 GMT</pubDate></item><item><title><![CDATA[Reply to atof und vector&amp;lt;string&amp;gt; on Wed, 08 Mar 2006 13:52:14 GMT]]></title><description><![CDATA[<p>YUHUUUU!! Das funktioniert...</p>
<p>Für die Alternative mit Funktoren bin ich nicht so weit...</p>
<p>Auf jeden Fall danke für die schnellen Antworten...Eine sehr effektive Hilfe...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1011596</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1011596</guid><dc:creator><![CDATA[carmen]]></dc:creator><pubDate>Wed, 08 Mar 2006 13:52:14 GMT</pubDate></item></channel></rss>