<?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[Probleme mit getline()?]]></title><description><![CDATA[<p>HALL0.</p>
<p>ich bin heute auf ein problem gestossen, dass ich mir nicht erklären kann. und zwar lese ich immer noch daten aus einer datei aus. ein beispiel für eine zeile ist folgende:</p>
<blockquote>
<p>13 14 8 9</p>
</blockquote>
<p>wenn ich diese mit</p>
<pre><code class="language-cpp">getline(datei,ZEILE);
</code></pre>
<p>einlese, steht dann in ZEILE:</p>
<blockquote>
<p>13 14 89</p>
</blockquote>
<p>aus 8 und 9 wurde also 89. woran liegt das?</p>
<p>DANKE.<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/162477/probleme-mit-getline</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 09:20:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/162477.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 19 Oct 2006 04:29:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 04:29:28 GMT]]></title><description><![CDATA[<p>HALL0.</p>
<p>ich bin heute auf ein problem gestossen, dass ich mir nicht erklären kann. und zwar lese ich immer noch daten aus einer datei aus. ein beispiel für eine zeile ist folgende:</p>
<blockquote>
<p>13 14 8 9</p>
</blockquote>
<p>wenn ich diese mit</p>
<pre><code class="language-cpp">getline(datei,ZEILE);
</code></pre>
<p>einlese, steht dann in ZEILE:</p>
<blockquote>
<p>13 14 89</p>
</blockquote>
<p>aus 8 und 9 wurde also 89. woran liegt das?</p>
<p>DANKE.<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1157375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157375</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Thu, 19 Oct 2006 04:29:28 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 05:42:17 GMT]]></title><description><![CDATA[<p>Zeigmal den Code wo du die Datei einliest (den ganzen Code). Sollt nämlich eigentlich keine Probleme dieser Art gegeben.</p>
<p>grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1157379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157379</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Thu, 19 Oct 2006 05:42:17 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 06:29:24 GMT]]></title><description><![CDATA[<p>HALL0.</p>
<p>der code sieht wie folgt aus:</p>
<pre><code class="language-cpp">int i,j,ZAHL;
	stringstream Str;
    string ZEILE;

    fstream datei;
    datei.open(pszFileName,ios::in);
    while (!datei.eof())
	{
        getline(datei,ZEILE);
	    for (i=0;i&lt;(int)ZEILE.size();i++)
		{
			if (ZEILE[i] == '/') break;
			if (ZEILE[i] == ' ')
			{
				if (0 != j)
				{
					Str &lt;&lt; ZEILE.substr(i-j,j);
					Str &gt;&gt; ZAHL;
					Str.clear();
				}

			}
			else j++;
		}
        if (j != 0)
        {
		   Str &lt;&lt; ZEILE[ZEILE.size()-1];
		   Str &gt;&gt; ZAHL;
		   Str.clear();
        }
    }
	datei.close();
</code></pre>
<p>VIELEN DANK!<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1157393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157393</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Thu, 19 Oct 2006 06:29:24 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 06:42:41 GMT]]></title><description><![CDATA[<p>Erstens hast du vergessen, j zu initialisieren.</p>
<p>Zweitens kommt mir deine Rechnerei mit den substr() etwas seltsam vor (ich komm da nicht mit, stimmen überhaupt die Start- und Endepositionen?).</p>
<p>Und drittens ist es wohl eleganter, den ganzen Block auf einmal in den Stream zu packen:</p>
<pre><code class="language-cpp">while(datei) // besser als 'nur' while(!datei.eof()) - fängt auch Lesefehler ab
{
  getline(datei, zeile);
  str.str(zeile);//gelesene Zeile in Stringstream schreiben
  while(str) //das hier bricht ab, wenn es eine Nicht-Zahl (also '/' oder das Zeilenende erreicht hat
  {
    str&gt;&gt;zahl;
    //zahl weiterverarbeiten
  }
  str.clear();
}
</code></pre>
<p>Viertens: Debugging hilft mitunter <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="😉"
    /> (zur Not setz einfach ein cout&lt;&lt;ZEILE&lt;&lt;endl; unter deinen getline())</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1157397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157397</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Oct 2006 06:42:41 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 07:31:20 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10318">@CStoll</a>:<br />
ich bin gerade dabei, deinen vorschlag abzuarbeiten. leider scheint das nicht zu funktionieren. wenn ich eine zeile habe, die mit einem '//' beginnt, wird bei mir auf dem bildschirm für ZAHL so etwas wie '-865242425' ausgedruckt. ist bei deinem vorschlag vielleicht noch etwas vergessen wurden?</p>
<pre><code>while (datei)
	{
        getline(datei,ZEILE);
		cout &lt;&lt; ZEILE &lt;&lt; endl;
		_getch();
		Str.str(ZEILE);
		while (Str)
		{
			Str  &gt;&gt; ZAHL;
			cout &lt;&lt; ZAHL &lt;&lt; &quot; &quot;;
			_getch();
		}
		cout &lt;&lt; &quot;\n\n&quot;;
		Str.clear();
	}
</code></pre>
<p>DANKE.<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1157413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157413</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Thu, 19 Oct 2006 07:31:20 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 07:37:53 GMT]]></title><description><![CDATA[<p>Ups, kleiner Fehler von mir - wenn das Lesen fehlgeschlagen ist, steht ja noch irgendwas in der Zielvariablen, also müsstest du vor der Weiterverarbeitung noch prüfen, ob der Stream noch intakt ist:</p>
<pre><code class="language-cpp">//altmodische Form:
while(str)
{
  str&gt;&gt;zahl;
  if(!str) break;
  cout&lt;&lt;zahl;
}

//kürzer und eleganter
while(str&gt;&gt;zahl)
//op&gt;&gt; liefert den Stream zurück, dessen Status anschließend von while() überprüft werden kann
{
  cout&lt;&lt;zahl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1157421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157421</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Oct 2006 07:37:53 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit getline()? on Thu, 19 Oct 2006 08:15:33 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10318">@CStoll</a>:</p>
<p>DANKE, jetzt klappts. ist WIRKLICH ein GUTES FORUM hier!!! <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/1157441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1157441</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Thu, 19 Oct 2006 08:15:33 GMT</pubDate></item></channel></rss>