<?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[Getline wird nicht beachtet]]></title><description><![CDATA[<p>Hallo alle miteinander,<br />
ich habe ein Problem mit</p>
<pre><code>void ver()
{
    string text;
    getline(cin, text);
    ofstream encode;
    encode.open(&quot;encode.txt&quot;);
    encode &lt;&lt; text;
    encode.close();
    return;
}
</code></pre>
<p>dieser Passage. Sie wird über switch aufgerufen jedoch bei Ausführung kann ich nichts Eingeben, was ja eigentlich durch getline() geschehen sollte.<br />
Ich lerne C++11 mit einem Buch und habe versucht selbst ein kleines Programm zu schreiben, blieb jedoch an dieser Stelle hängen.<br />
Ich wäre sehr froh, wenn mich jemand auf meinen Fehler hinweisen würde, damit ich ihn beseitigen kann.<br />
Vielen Dank im vorraus. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>MFG JBHillmann</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326775/getline-wird-nicht-beachtet</link><generator>RSS for Node</generator><lastBuildDate>Sat, 30 May 2026 17:53:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326775.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Jul 2014 19:21:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:21:16 GMT]]></title><description><![CDATA[<p>Hallo alle miteinander,<br />
ich habe ein Problem mit</p>
<pre><code>void ver()
{
    string text;
    getline(cin, text);
    ofstream encode;
    encode.open(&quot;encode.txt&quot;);
    encode &lt;&lt; text;
    encode.close();
    return;
}
</code></pre>
<p>dieser Passage. Sie wird über switch aufgerufen jedoch bei Ausführung kann ich nichts Eingeben, was ja eigentlich durch getline() geschehen sollte.<br />
Ich lerne C++11 mit einem Buch und habe versucht selbst ein kleines Programm zu schreiben, blieb jedoch an dieser Stelle hängen.<br />
Ich wäre sehr froh, wenn mich jemand auf meinen Fehler hinweisen würde, damit ich ihn beseitigen kann.<br />
Vielen Dank im vorraus. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>MFG JBHillmann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407279</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:21:16 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:23:11 GMT]]></title><description><![CDATA[<p>Haste vorher zufällig einen int eingelesen und das \n nach dem int hängt noch im Eingavepuffer rum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407280</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407280</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:23:11 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:25:33 GMT]]></title><description><![CDATA[<p>Nein das kann nicht sein dies ist das erste das eingelesen wird...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407281</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407281</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:25:33 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:31:45 GMT]]></title><description><![CDATA[<p>Da ist so erstmal kein Fehler drin.<br />
Zeig mehr Code...</p>
<p>Bzw: Step mal mim Debugger durch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407282</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:31:45 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:36:41 GMT]]></title><description><![CDATA[<p>An dem Code fällt mir keine Fehler auf. Also ist er in einem anderen Programmteil, zum Beispiel beim Funktionsaufruf die Klammern vergessen. Müßtest den Rest des Programms auch zeigen. Optimalerweise so, daß wir es einfach auf dem eigenen Rechner ausprobieren können, also ein kleines aber vollständiges Programm.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407283</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:39:18 GMT]]></title><description><![CDATA[<p>Hier ist der code der bis zu dieser stelle verwendet wird...<br />
Sonstige Verbesserungsvorschläge auch gerne erwünscht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

void rig();
void start();
void ver();
void ent();
void bad();
void ende();

bool sv1{1}, sv2{1};

int main()
{
    if (::sv2)
    {
        rig();
    }
    if (::sv1)
    {
    start();
    }
    return 0;
}

void rig()
{
    cout &lt;&lt; &quot;Krypto \n VERSION 1.3\n ENGLISH \n ALL RIGHTS RESERVED BY JBD \n&quot;;
    sv2=0;
    return;
}

void start()
{
    cout &lt;&lt; &quot;\n [A] Text encoding&quot;;
    cout &lt;&lt; &quot;\n [B] Text decoding&quot;;
    cout &lt;&lt; &quot;\n [E] End&quot;;
    cout &lt;&lt; &quot;\n \n Your input: &quot;;
    char want{0};
    cin &gt;&gt; want;
    switch (want)
    {
        case 'A': ver(); break;
        case 'a': ver(); break;
        case 'B': ent(); break;
        case 'b': ent(); break;
        case 'E': ende(); break;
        case 'e': ende(); break;
        default: bad();
    }
    main();
}

void ver()
{
    string text;
    getline(cin, text);
    ofstream encode;
    encode.open(&quot;encode.txt&quot;);
    encode &lt;&lt; text;
    encode.close();
    return;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2407284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407284</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:39:18 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:42:22 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Haste vorher zufällig einen int eingelesen und das \n nach dem int hängt noch im Eingavepuffer rum?</p>
</blockquote>
<p>JBHillmann schrieb:</p>
<blockquote>
<p>Nein das kann nicht sein dies ist das erste das eingelesen wird...</p>
</blockquote>
<p>JBHillmann schrieb:</p>
<blockquote>
<p>cin &gt;&gt; want;</p>
</blockquote>
<p>Zwar kein int sondern ein char, hat aber den gleichen Effekt.</p>
<p>Sonstige Verbesserungswünsche: Lass die globalen Variablen raus, ruf main nicht rekursiv auf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407286</guid><dc:creator><![CDATA[patrick246]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:42:22 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:45:13 GMT]]></title><description><![CDATA[<p>patrick246 schrieb:</p>
<blockquote>
<p>Sonstige Verbesserungswünsche: Lass die globalen Variablen raus, ruf main nicht rekursiv auf.</p>
</blockquote>
<p>main rekursiv aufzurufen ist nicht einmal erlaubt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407288</guid><dc:creator><![CDATA[mainrec]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:45:13 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:45:14 GMT]]></title><description><![CDATA[<p>JBHillmann schrieb:</p>
<blockquote>
<p>Sonstige Verbesserungsvorschläge auch gerne erwünscht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
</blockquote>
<p>Dieses Buch schnell wegwerfen! Das ist kein C++, sondern irgendwas anderes. Erinnert an Wolf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407289</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:45:14 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:47:05 GMT]]></title><description><![CDATA[<p>Ok danke und wie kann ich das beheben?<br />
Was bedeutet</p>
<p>patrick246 schrieb:</p>
<blockquote>
<p>ruf main nicht rekursiv auf.</p>
</blockquote>
<p>?</p>
<p>Ist tatsächlich das Buch von Jürgen WOlf <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2407290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407290</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:47:05 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:47:27 GMT]]></title><description><![CDATA[<p>JBHillmann schrieb:</p>
<blockquote>
<p>Ok danke und wie kann ich das beheben?<br />
Was bedeutet</p>
<p>patrick246 schrieb:</p>
<blockquote>
<p>ruf main nicht rekursiv auf.</p>
</blockquote>
<p>?</p>
</blockquote>
<p>Schreib nicht main() als Funktionsaufruf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407291</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:47:27 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:52:02 GMT]]></title><description><![CDATA[<p>Ahh ok danke<br />
werd ich ändern<br />
und was ist jetzt mit dem eigentlichen Problem? wie bekomm ich das \n<br />
das im Eingabepuffer gammelt weg?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407292</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:52:02 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 19:56:29 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/istream/istream/ignore/" rel="nofollow">http://www.cplusplus.com/reference/istream/istream/ignore/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407293</guid><dc:creator><![CDATA[patrick246]]></dc:creator><pubDate>Sun, 06 Jul 2014 19:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:00:05 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;limits&gt;

cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n'); // verwirf max() Zeichen, bis du auf newline oder EOF stößt
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2407294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407294</guid><dc:creator><![CDATA[Jodocus]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:00:05 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:00:54 GMT]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

//Vorwärtsdeklarationen sind eigentlich nicht nötig. Sinnlos viel Arbeit. 
//Schlechte Namen, als Leser erkenne ich nicht, was die machen. 
void rig();
void start();
void ver();
void ent();
void bad();
void ende();

//Uniforme Initialisierung ist hier fürn Popo. 
//Und bools mit 1 initialisieren? true!!!
//Das ist ja C und kein C++. 
//sv? Sagt mir nix. 
bool sv1{1}, sv2{1};

int main()
{
    if (::sv2)
    {
        rig();
    }
    if (::sv1)
    {
    start();
    }
    return 0;//darf man weglassen
}

void rig()
{
    cout &lt;&lt; &quot;Krypto \n VERSION 1.3\n ENGLISH \n ALL RIGHTS RESERVED BY JBD \n&quot;;//\n am ENDE
    sv2=0;//false
    return;//störend
}

void start()
{
    cout &lt;&lt; &quot;\n [A] Text encoding&quot;;//\n am ANFANG, inkonsistent.
    cout &lt;&lt; &quot;\n [B] Text decoding&quot;;
    cout &lt;&lt; &quot;\n [E] End&quot;;
    cout &lt;&lt; &quot;\n \n Your input: &quot;;
    char want{0};//Wozu auf 0 setzen? Warum die häßliche {}-Syntax? 
    cin &gt;&gt; want;
    switch (want)
    {
        case 'A': ver(); break;
        case 'a': ver(); break;
        case 'B': ent(); break;
        case 'b': ent(); break;
        case 'E': case 'e': ende(); break;//oder einfach so:
        default: bad();
    }
    main();//verboten!
}

void ver()
{
    string text;//später
    getline(cin, text);
    ofstream encode;//konstuktor
    encode.open(&quot;encode.txt&quot;);//konstruktor!
    encode &lt;&lt; text;
    encode.close();//DESTRUKTOR!!!
    return;//sinnlos
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2407295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407295</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:00:54 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:14:37 GMT]]></title><description><![CDATA[<p>Ok Problem gelöst funktioniert nun <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Vielen Dank an euch<br />
und wiedermal sehe ich wie ich als Anfänger extrem viel zu lernen habe und das hier dinge kritisiert werden die ich meinem &quot;Lernbuch&quot; gleichtue...<br />
Soll ich anstant Vorwärtsdeklarationen zu machen die main() ans Ende setzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407296</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:14:37 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:16:55 GMT]]></title><description><![CDATA[<p>JBHillmann schrieb:</p>
<blockquote>
<p>Soll ich anstant Vorwärtsdeklarationen zu machen die main() ans Ende setzen?</p>
</blockquote>
<p>Ja.<br />
Und FALLS doch mal eine gebrauch werden würde, kannste immernoch eine machen.</p>
<p>Hier wird sie gebraucht, weil sich Funktionen gegenseitig aufrufen. Aber der main()-Trick ist eh nicht gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407298</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:16:55 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:23:45 GMT]]></title><description><![CDATA[<p>Problem: Die start() gibt keinen bool zurück!</p>
<p>Gute Lösung:</p>
<pre><code>int main()
{
   cout &lt;&lt; &quot;Krypto \n VERSION 1.3\n ENGLISH \n ALL RIGHTS RESERVED BY JBD \n&quot;;
   while(start())
	   ;
}
</code></pre>
<p>Seine start() gibt nix zurück, aber genau dort kann er nur feststellen, ob der Benutzer aufhören will. Also ruft der Auto die main() auf. Mit dem Problem, daß der Into-Text immer kommt und nicht nur einmal, also legt er globale Variablen an und schreibt</p>
<pre><code>if (::sv2)
    {
        rig();
    }
</code></pre>
<p>Wie schrecklich. Und abgesehen von allen Dummheiten steckt einfach in jedem Detail Mist. Zum Beispiel hätte es sein sollen</p>
<pre><code>if (sv2)
    {
        rig();
	sv2=false;
    }
</code></pre>
<p>dann sieht man hier, was das bedeuten soll: Nur einmal anzeigen. Die Zuweisung wegzuverstecken hilft doch genau gar keinem. Ich bin mit dem Code runherum nicht einverstanden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407299</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:23:45 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:25:10 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<pre><code>ofstream encode;//konstuktor
    encode.open(&quot;encode.txt&quot;);//konstruktor!
    encode &lt;&lt; text;
    encode.close();//DESTRUKTOR!!!
    return;//sinnlos
}
</code></pre>
</blockquote>
<p>und warum regt man sich hier über encode.close(); auf?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407300</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:25:10 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:29:03 GMT]]></title><description><![CDATA[<p>JBHillmann schrieb:</p>
<blockquote>
<p>und warum regt man sich hier über encode.close(); auf?</p>
</blockquote>
<p>Weil Du später Code schreiben wirst, der überall Exceptions werfen könnte, und da bringt close() nichts mehr. Also wozu erst angewöhnen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407301</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:29:03 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:30:01 GMT]]></title><description><![CDATA[<p>Weil es unnötig ist. encode wird automatisch mit verlassen des Scopes geschlossen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407302</guid><dc:creator><![CDATA[patrick246]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:30:01 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 20:33:30 GMT]]></title><description><![CDATA[<p>ohh ok also schlicht unnötig</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407303</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Sun, 06 Jul 2014 20:33:30 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Mon, 07 Jul 2014 07:14:37 GMT]]></title><description><![CDATA[<pre><code>ofstream encode;//konstuktor
encode.open(&quot;encode.txt&quot;);//konstruktor!
</code></pre>
<p>und hier ist was falsch? Ohne eins von beidem funktionierts nicht?</p>
<p>~(Edit v. Arcoth, Code-Tags)~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407304</guid><dc:creator><![CDATA[JBHillmann]]></dc:creator><pubDate>Mon, 07 Jul 2014 07:14:37 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 21:02:28 GMT]]></title><description><![CDATA[<p>JBHillmann schrieb:</p>
<blockquote>
<p>ofstream encode;//konstuktor<br />
encode.open(&quot;encode.txt&quot;);//konstruktor!</p>
<p>und hier ist was falsch? Ohne eins von beidem funktionierts nicht?</p>
</blockquote>
<pre><code>ofstream encode(&quot;encode.txt&quot;);//Diesen Konstruktor benutzen statt Defaultkonstruktor und open.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2407305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407305</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 06 Jul 2014 21:02:28 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 21:37:20 GMT]]></title><description><![CDATA[<p>JBHillmann schrieb:</p>
<blockquote>
<p>und warum regt man sich hier über encode.close(); auf?</p>
</blockquote>
<p>Unnötiges Ressourcenschliessen ist ein typisches Anzeichen dafür, dass Leute RAII -- und damit eines der wichtigsten Konzepte in C++ überhaupt -- nicht verstanden haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407308</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 06 Jul 2014 21:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to Getline wird nicht beachtet on Sun, 06 Jul 2014 21:46:21 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>JBHillmann schrieb:</p>
<blockquote>
<p>und warum regt man sich hier über encode.close(); auf?</p>
</blockquote>
<p>Unnötiges Ressourcenschliessen ist ein typisches Anzeichen dafür, dass Leute RAII -- und damit eines der wichtigsten Konzepte in C++ überhaupt -- nicht verstanden haben.</p>
</blockquote>
<p>Ein close() hinauszuzögern nur weil der Code dadurch kompakter wird ist ein typisches Anzeichen dafür, dass Leute die Nachteile von RAII bewusst ignorieren.</p>
<p>Hier kommt es vielleicht auf das gleiche drauf raus, aber wenn schon mit Exceptions argumentiert wird darf ich auch den allgemeinen Fall betrachten:</p>
<pre><code class="language-cpp">ofstream encode(&quot;encode.txt&quot;);
encode &lt;&lt; &quot;test&quot;;

&lt;berechnung&gt;
return &lt;something&gt;
</code></pre>
<p>Die Datei wird hier erst am Ende des Scopes geschlossen. Die maximale Anzahl offener Dateien ist sehr beschrängt, wenn bei <code>&lt;berechnung&gt;</code> nochmal eine Datei geöffnet wird, hat man u.U. Probleme. Besser:</p>
<pre><code class="language-cpp">ofstream encode(&quot;encode.txt&quot;);
encode &lt;&lt; &quot;test&quot;;
auto position = encode.tellg(); // einfach damit man encode nicht so einfach in einen Block stecken kann
endode.close(); // nicht mehr benötigt =&gt; sofort zumachen

&lt;berechnung&gt;
return &lt;something&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2407310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407310</guid><dc:creator><![CDATA[releaseearlyandoften]]></dc:creator><pubDate>Sun, 06 Jul 2014 21:46:21 GMT</pubDate></item></channel></rss>