<?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[fstream + getline fehler bei verwendung von string!]]></title><description><![CDATA[<p>ich möchte einzelne zeilen in ein string array abspeichern.<br />
dazu habe ich diesen code hier:</p>
<pre><code class="language-cpp">#include &quot;string.h&quot;
.....
....
string stringarray[999];
....
...

	fstream f(&quot;kA.kA&quot;, ios::in);
	while(!f.eof())
	{
		f.getline((char*)stringarray[1],5);
		i++;
	};
</code></pre>
<p>allerdings bekomme ich dabei immer einen fehler:</p>
<blockquote>
<p>error C2440: 'type cast' : cannot convert from 'std::string' to 'char *'</p>
</blockquote>
<p>was kann man da machen??<br />
und wie kann man ein array mit unbestimmter größe deklarieren ohne eine fehlermeldung wegen einem zero array zu bekommen??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/207423/fstream-getline-fehler-bei-verwendung-von-string</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 07:01:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/207423.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 Mar 2008 12:37:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 12:38:32 GMT]]></title><description><![CDATA[<p>ich möchte einzelne zeilen in ein string array abspeichern.<br />
dazu habe ich diesen code hier:</p>
<pre><code class="language-cpp">#include &quot;string.h&quot;
.....
....
string stringarray[999];
....
...

	fstream f(&quot;kA.kA&quot;, ios::in);
	while(!f.eof())
	{
		f.getline((char*)stringarray[1],5);
		i++;
	};
</code></pre>
<p>allerdings bekomme ich dabei immer einen fehler:</p>
<blockquote>
<p>error C2440: 'type cast' : cannot convert from 'std::string' to 'char *'</p>
</blockquote>
<p>was kann man da machen??<br />
und wie kann man ein array mit unbestimmter größe deklarieren ohne eine fehlermeldung wegen einem zero array zu bekommen??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1469985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1469985</guid><dc:creator><![CDATA[halo]]></dc:creator><pubDate>Fri, 07 Mar 2008 12:38:32 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 12:42:42 GMT]]></title><description><![CDATA[<p>wie wäre es wenn du es so machst</p>
<pre><code class="language-cpp">int i = 0;
while(getline(f,stringarray[i])
    {

        i++;
    };
</code></pre>
<p>ist aber ungetestet</p>
<p>achja es heißt nicht #include &quot; string.h&quot; sondern<br />
#include&lt;string&gt;</p>
<p>außer du hast dir eine eigene string klasse geschrieben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1469993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1469993</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Fri, 07 Mar 2008 12:42:42 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 12:44:09 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>benutz std::vector ( eine Art Array, welches seine Größe dynamisch selbst verwaltet ), dann hast du dein Problem mit deiner unbestimmten Größe schonmal nicht.</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
    vector&lt;string&gt; stringarray;
    ifstream file(&quot;kA.kA&quot;);

    string tmp = &quot;&quot;;
    while( getline( file, tmp ) ) stringarray.push_back(tmp);
}
</code></pre>
<p>Danach kannst du gewohnt mit stringarray[ index ] arbeiten ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1469996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1469996</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 07 Mar 2008 12:44:09 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 13:02:07 GMT]]></title><description><![CDATA[<p>Versuchs mal mit</p>
<pre><code>f.getline((stringarray[1].c_str(),5);
</code></pre>
<p>Du kannst natürlich nicht ein Stringobjekt in einen char Zeiger casten. c_str() gubt Dir einen Zeiger auf den Null terminierten String</p>
<p>Mfg Mav</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470008</guid><dc:creator><![CDATA[Mav_80]]></dc:creator><pubDate>Fri, 07 Mar 2008 13:02:07 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 13:50:37 GMT]]></title><description><![CDATA[<p>danke ich werd alles mal ausprobiern</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470042</guid><dc:creator><![CDATA[halo]]></dc:creator><pubDate>Fri, 07 Mar 2008 13:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 14:01:35 GMT]]></title><description><![CDATA[<p>aber .c_str() gibt einen const-char-Zeiger zurück.<br />
Also kann getline() da nich reinschreiben.</p>
<p>Afaik kann man der getline-Methode gar keinen String übergeben. Du brauchst also ein char-Array.<br />
Du müsstest es also so ungefähr machen:</p>
<pre><code class="language-cpp">vector&lt;string&gt; stringarray;
    fstream f(&quot;kA.kA&quot;, ios::in);
    while(!f.eof())
    {
        char buf[256]; // vllt. anpassen
        f.getline(buf, 256);
        stringarray.push_back(buf);
    };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1470051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470051</guid><dc:creator><![CDATA[pyromania]]></dc:creator><pubDate>Fri, 07 Mar 2008 14:01:35 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 14:04:06 GMT]]></title><description><![CDATA[<p>Beunutze die std::getline(..) Funktion (Header: &lt;string&gt;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470052</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Fri, 07 Mar 2008 14:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 14:26:06 GMT]]></title><description><![CDATA[<p>ok danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470059</guid><dc:creator><![CDATA[halo]]></dc:creator><pubDate>Fri, 07 Mar 2008 14:26:06 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 15:10:37 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/17930">@halo</a>: Alles andere ist nur gefrickel und kein schönes C++. Mach dich mit dem vertraut, was ich geschrieben habe und bleib dabei. Bei unklare Stellen im Code kannst du ja nachfragen <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/1470085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470085</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 07 Mar 2008 15:10:37 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 21:34:55 GMT]]></title><description><![CDATA[<p>ok</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470331</guid><dc:creator><![CDATA[halo]]></dc:creator><pubDate>Fri, 07 Mar 2008 21:34:55 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 21:47:55 GMT]]></title><description><![CDATA[<p>ich hab das ganze jetzt in eine klasse eingebaut, um den quelltext ein wenig ordentlicher zu gestalten!<br />
allerdings kommt jetzt dieser fehler hier:</p>
<pre><code>error C2864: 'Cfile::tmp' : only static const integral data members can be initialized within a class
</code></pre>
<p>das bezieht sich auf diese zeile:</p>
<pre><code class="language-cpp">string tmp = &quot;&quot;;
</code></pre>
<p>wie kann man diesen fehler umgehn??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470333</guid><dc:creator><![CDATA[halo]]></dc:creator><pubDate>Fri, 07 Mar 2008 21:47:55 GMT</pubDate></item><item><title><![CDATA[Reply to fstream + getline fehler bei verwendung von string! on Fri, 07 Mar 2008 21:52:29 GMT]]></title><description><![CDATA[<p>ok hab die lösung gefunden!!<br />
einfach erst im konstruktor deklarieren!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1470335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1470335</guid><dc:creator><![CDATA[halo]]></dc:creator><pubDate>Fri, 07 Mar 2008 21:52:29 GMT</pubDate></item></channel></rss>