<?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[Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung]]></title><description><![CDATA[<p>Warum bricht er da nicht ab:</p>
<pre><code class="language-cpp">int main()
{
    string temp;
    string save;
    while(cin &gt;&gt; temp)
    {
        if(save != &quot;&quot; &amp;&amp; save == temp)
        {
            cout &lt;&lt; &quot;Same word order!&quot; &lt;&lt; endl;
            cout &lt;&lt; save &lt;&lt; &quot; = &quot; &lt;&lt; temp &lt;&lt; endl;
            break;
        }
        if(temp[temp.size()] == '\n') // HIER!
        {
            cout &lt;&lt; &quot;CIN-Buffer read to end!&quot; &lt;&lt; endl;
            break;
        }
        save = temp;
    }
</code></pre>
<p>Wenn ich zum Beispiel &quot;Er zieht durchs Land&quot; eingebe, dann müsste doch beim letzten ausgelesenen Wort der letzte Buchstabe '\n' sein (weil man ja mit Enter die Eingabe bestätigt)? Und somit könnte ich erkennen, ob ich beenden will oder nicht?<br />
Was mach ich falsch?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/238085/schleife-bricht-nicht-ab-bei-quot-n-quot-bedingung</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 05:28:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/238085.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Apr 2009 11:21:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 11:21:45 GMT]]></title><description><![CDATA[<p>Warum bricht er da nicht ab:</p>
<pre><code class="language-cpp">int main()
{
    string temp;
    string save;
    while(cin &gt;&gt; temp)
    {
        if(save != &quot;&quot; &amp;&amp; save == temp)
        {
            cout &lt;&lt; &quot;Same word order!&quot; &lt;&lt; endl;
            cout &lt;&lt; save &lt;&lt; &quot; = &quot; &lt;&lt; temp &lt;&lt; endl;
            break;
        }
        if(temp[temp.size()] == '\n') // HIER!
        {
            cout &lt;&lt; &quot;CIN-Buffer read to end!&quot; &lt;&lt; endl;
            break;
        }
        save = temp;
    }
</code></pre>
<p>Wenn ich zum Beispiel &quot;Er zieht durchs Land&quot; eingebe, dann müsste doch beim letzten ausgelesenen Wort der letzte Buchstabe '\n' sein (weil man ja mit Enter die Eingabe bestätigt)? Und somit könnte ich erkennen, ob ich beenden will oder nicht?<br />
Was mach ich falsch?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691705</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Mon, 06 Apr 2009 11:21:45 GMT</pubDate></item><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 11:24:05 GMT]]></title><description><![CDATA[<blockquote>
<p>Wenn ich zum Beispiel &quot;Er zieht durchs Land&quot; eingebe, dann müsste doch beim letzten ausgelesenen Wort der letzte Buchstabe '\n' sein (weil man ja mit Enter die Eingabe bestätigt)? Und somit könnte ich erkennen, ob ich beenden will oder nicht?</p>
</blockquote>
<p>Enter ist aber \r.</p>
<p>Guck doch mal was drin steht...<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691708</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 06 Apr 2009 11:24:05 GMT</pubDate></item><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 11:25:50 GMT]]></title><description><![CDATA[<p>verusch mal temp.size() - 1 weil temp.size() hinter dem letzten ist</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691709</guid><dc:creator><![CDATA[tempsize]]></dc:creator><pubDate>Mon, 06 Apr 2009 11:25:50 GMT</pubDate></item><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 11:30:15 GMT]]></title><description><![CDATA[<p>Weder mit '\r' nocht mit size() -1 funktionirt es <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691712</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Mon, 06 Apr 2009 11:30:15 GMT</pubDate></item><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 11:35:32 GMT]]></title><description><![CDATA[<p><code>\r\n</code> wird bei dieser Anweisung gar nicht erst eingelesen. Das Zeug bleibt im <code>std::cin</code> Puffer drin und kommt nicht in deine <code>temp</code> Variable. Leerzeichen werden bei <code>operator &gt;&gt;</code> standardmässig ignoriert.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691716</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 06 Apr 2009 11:35:32 GMT</pubDate></item><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 12:17:05 GMT]]></title><description><![CDATA[<p>Und wie würdest du dann die Abbruchbedingung gestalten? Also für des Enter, wenn alle Wörter eingelesen wurden?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691738</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691738</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:17:05 GMT</pubDate></item><item><title><![CDATA[Reply to Schleife bricht nicht ab bei &amp;quot; == &#x27;&#x5C;n&#x27;&amp;quot; Bedingung on Mon, 06 Apr 2009 12:27:43 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;sstream&gt;   // Für std::istringstream
#include &lt;iostream&gt;

int main()
{
  std::string line;
  std::geline(std::cin, line);

  // Verwende nun zum Beispiel Boost.Tokenizer
  // oder trenne die Teile von Hand auf.

  // Du kannst auch sowas machen:
  std::string word;
  std::istringstream iss(line);

  // iss ist so lange gültig, wie es etwas im Puffer hat.
  // Sobald also das ende von line erreicht wurde,
  // bricht die Schleife ab.
  while(iss &gt;&gt; word)
  {
    // ...
  }

  // ...

  return 0;
}
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691744</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:27:43 GMT</pubDate></item></channel></rss>