<?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[Erstes kleines Konsolenprogramm zum Bewerten]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich arbeite nun seit einigen Tagen mit C++ und wollte euch mal hier meinen Code vorstellen und ihn mal zur Korrektur bzw. Feedback vorlegen.</p>
<p>Es ist ein simples kleines Programm, das auf der Konsole startet.<br />
Was macht es?<br />
Es ist ein Gästebuch, d.h. man trägt seinen Namen, EIntrag ein und das Ergebnis wird in einer Textdatei gespeichert zusätzlich mit einem Timestamp.<br />
Die Eingaben des Users werden auch überprüft. Z.B. muss man beim Namen mindestens 2 Buchstaben, beim EIntrag mindestens 5 eingeben.</p>
<p>Ich habe mir auch noch eine zusätzliche Hilfsklasse mit einer statischen Methode erstellt, die mir int in String umwandelt und den wert returnt.</p>
<p>Ich hoffe, jemand kann sich mal die Zeit nehmen, ein Blick drüberwerfen und mir Verbesserungsvorschläge, oder elegantere Lösungen zu meinem Projekt vorzeigen.</p>
<p>Danke im voraus und hier der Code:</p>
<p>**<br />
castutils.h**</p>
<pre><code class="language-cpp">#ifndef CASTUTILS_H
#define CASTUTILS_H

#include &lt;string&gt;

using namespace std;

class CastUtils{
    public:
       static string intToString(int i);
};

#endif // CASTUTILS_H
</code></pre>
<p><strong>gaestebuch.h</strong></p>
<pre><code class="language-cpp">#ifndef GAESTEBUCH_H
#define GAESTEBUCH_H

#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

class Gaestebuch{
    public:
        Gaestebuch();
        ~Gaestebuch();

    private:
        bool checkInputs(string name, string entry);

};

#endif // GAESTEBUCH_H
</code></pre>
<p>castutils.cpp</p>
<pre><code class="language-cpp">#include &quot;castutils.h&quot;
#include &lt;sstream&gt;
#include &lt;string&gt;

using namespace std;

string CastUtils::intToString(int i){
    ostringstream str;
    str &lt;&lt; i;
    return str.str();
}
</code></pre>
<p>gaestebuch.cpp</p>
<pre><code class="language-cpp">#include &quot;gaestebuch.h&quot;
#include &quot;castutils.h&quot;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;time.h&gt;

using namespace std;

Gaestebuch::Gaestebuch(){
    string name;
    string entry;
    bool end = false;
    string decision;

    ofstream txtFile;
    txtFile.open(&quot;Gaestebuch.txt&quot;, ios::app);

    while(!end){
        cout &lt;&lt; &quot;***************************************&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;Name:&quot; &lt;&lt; endl;
        cin.sync(); //nötig wegen getline()
        getline(cin, name);
        cout &lt;&lt; endl;
        cout &lt;&lt; &quot;Eintrag:&quot; &lt;&lt; endl;
        getline(cin, entry);
        cout &lt;&lt; endl;

        if(checkInputs(name, entry)){
            time_t timestamp = time(0);
            tm *now = localtime(&amp;timestamp);
            string time =
                    &quot; am &quot;+CastUtils::intToString(now-&gt;tm_mday) +
                    &quot;.&quot;+CastUtils::intToString(now-&gt;tm_mon)+
                    &quot;.&quot;+CastUtils::intToString(now-&gt;tm_year+1900)+

                    &quot; um &quot;+CastUtils::intToString(now-&gt;tm_hour)+
                    &quot;:&quot;+CastUtils::intToString(now-&gt;tm_min)+
                    &quot; Uhr&quot;;

            txtFile &lt;&lt; &quot;von &quot; &lt;&lt; name &lt;&lt; time &lt;&lt; endl
                    &lt;&lt; entry &lt;&lt; endl
                    &lt;&lt; endl;
        }
        else{
            cout &lt;&lt; &quot;#Fehler! Bitte pruefen Sie Laenge Ihrer Eingaben(Name min 2 Zeichen, Eintrag min 5 Zeichen.)&quot; &lt;&lt; endl &lt;&lt; endl;
        }

        cout &lt;&lt; &quot;Weiteren Eintrag hinzufuegen?(J = Ja - N = Nein)&quot; &lt;&lt; endl;
        getline(cin, decision);
        if(decision == &quot;N&quot;){
            end = true;
            txtFile.close();
            cout &lt;&lt; endl;
        }
    }
}

bool Gaestebuch::checkInputs(string name, string entry){
    if(name.length() &lt;= 2 &amp;&amp; entry.length() &lt;= 5){
        return false;
    }
    return true;
}
</code></pre>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;gaestebuch.h&gt;

void main()
{
    Gaestebuch *gb = new Gaestebuch;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/310079/erstes-kleines-konsolenprogramm-zum-bewerten</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 02:33:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/310079.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Nov 2012 11:48:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 11:59:42 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich arbeite nun seit einigen Tagen mit C++ und wollte euch mal hier meinen Code vorstellen und ihn mal zur Korrektur bzw. Feedback vorlegen.</p>
<p>Es ist ein simples kleines Programm, das auf der Konsole startet.<br />
Was macht es?<br />
Es ist ein Gästebuch, d.h. man trägt seinen Namen, EIntrag ein und das Ergebnis wird in einer Textdatei gespeichert zusätzlich mit einem Timestamp.<br />
Die Eingaben des Users werden auch überprüft. Z.B. muss man beim Namen mindestens 2 Buchstaben, beim EIntrag mindestens 5 eingeben.</p>
<p>Ich habe mir auch noch eine zusätzliche Hilfsklasse mit einer statischen Methode erstellt, die mir int in String umwandelt und den wert returnt.</p>
<p>Ich hoffe, jemand kann sich mal die Zeit nehmen, ein Blick drüberwerfen und mir Verbesserungsvorschläge, oder elegantere Lösungen zu meinem Projekt vorzeigen.</p>
<p>Danke im voraus und hier der Code:</p>
<p>**<br />
castutils.h**</p>
<pre><code class="language-cpp">#ifndef CASTUTILS_H
#define CASTUTILS_H

#include &lt;string&gt;

using namespace std;

class CastUtils{
    public:
       static string intToString(int i);
};

#endif // CASTUTILS_H
</code></pre>
<p><strong>gaestebuch.h</strong></p>
<pre><code class="language-cpp">#ifndef GAESTEBUCH_H
#define GAESTEBUCH_H

#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

class Gaestebuch{
    public:
        Gaestebuch();
        ~Gaestebuch();

    private:
        bool checkInputs(string name, string entry);

};

#endif // GAESTEBUCH_H
</code></pre>
<p>castutils.cpp</p>
<pre><code class="language-cpp">#include &quot;castutils.h&quot;
#include &lt;sstream&gt;
#include &lt;string&gt;

using namespace std;

string CastUtils::intToString(int i){
    ostringstream str;
    str &lt;&lt; i;
    return str.str();
}
</code></pre>
<p>gaestebuch.cpp</p>
<pre><code class="language-cpp">#include &quot;gaestebuch.h&quot;
#include &quot;castutils.h&quot;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;time.h&gt;

using namespace std;

Gaestebuch::Gaestebuch(){
    string name;
    string entry;
    bool end = false;
    string decision;

    ofstream txtFile;
    txtFile.open(&quot;Gaestebuch.txt&quot;, ios::app);

    while(!end){
        cout &lt;&lt; &quot;***************************************&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;Name:&quot; &lt;&lt; endl;
        cin.sync(); //nötig wegen getline()
        getline(cin, name);
        cout &lt;&lt; endl;
        cout &lt;&lt; &quot;Eintrag:&quot; &lt;&lt; endl;
        getline(cin, entry);
        cout &lt;&lt; endl;

        if(checkInputs(name, entry)){
            time_t timestamp = time(0);
            tm *now = localtime(&amp;timestamp);
            string time =
                    &quot; am &quot;+CastUtils::intToString(now-&gt;tm_mday) +
                    &quot;.&quot;+CastUtils::intToString(now-&gt;tm_mon)+
                    &quot;.&quot;+CastUtils::intToString(now-&gt;tm_year+1900)+

                    &quot; um &quot;+CastUtils::intToString(now-&gt;tm_hour)+
                    &quot;:&quot;+CastUtils::intToString(now-&gt;tm_min)+
                    &quot; Uhr&quot;;

            txtFile &lt;&lt; &quot;von &quot; &lt;&lt; name &lt;&lt; time &lt;&lt; endl
                    &lt;&lt; entry &lt;&lt; endl
                    &lt;&lt; endl;
        }
        else{
            cout &lt;&lt; &quot;#Fehler! Bitte pruefen Sie Laenge Ihrer Eingaben(Name min 2 Zeichen, Eintrag min 5 Zeichen.)&quot; &lt;&lt; endl &lt;&lt; endl;
        }

        cout &lt;&lt; &quot;Weiteren Eintrag hinzufuegen?(J = Ja - N = Nein)&quot; &lt;&lt; endl;
        getline(cin, decision);
        if(decision == &quot;N&quot;){
            end = true;
            txtFile.close();
            cout &lt;&lt; endl;
        }
    }
}

bool Gaestebuch::checkInputs(string name, string entry){
    if(name.length() &lt;= 2 &amp;&amp; entry.length() &lt;= 5){
        return false;
    }
    return true;
}
</code></pre>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;gaestebuch.h&gt;

void main()
{
    Gaestebuch *gb = new Gaestebuch;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2266856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266856</guid><dc:creator><![CDATA[Kenan]]></dc:creator><pubDate>Sat, 03 Nov 2012 11:59:42 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 12:21:20 GMT]]></title><description><![CDATA[<p>Die Klassen sind bei dir vollkommen sinnlos. Das komplette Programm kann genau so auch mit freien Funktionen implementiert werde.<br />
void main muss int main sein.<br />
Warum new in der main?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266867</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 03 Nov 2012 12:21:20 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 13:45:39 GMT]]></title><description><![CDATA[<p>Das ist quasi ganz alter C++-Style, wo Klassen noch das tollste, neuste und beste waren, sodass man unbedingt alles in Klassen packen musste.<br />
Kapsel dir doch lieber einen Gästebucheintrag, speicher im Gästebuch einen <code>vector&lt;Eintrag&gt;</code> , mach den Timestamp mit <code>&lt;chrono&gt;</code> und lass das new/delete (delete hast du vergessen) dort, wo es hingehört - im tiefen Sumpf der für Anfänger gefährlichen Programmiersünden.<br />
Versuch jeder Klasse ihre Aufgaben zu geben, und die, welche nicht die ihren sind, reicht sie an andere Klassen weiter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266894</guid><dc:creator><![CDATA[Der Tobi]]></dc:creator><pubDate>Sat, 03 Nov 2012 13:45:39 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 14:08:31 GMT]]></title><description><![CDATA[<p>und</p>
<pre><code class="language-cpp">using namespace std;
</code></pre>
<p>in Headerdateien - keine gute Idee.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266906</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Sat, 03 Nov 2012 14:08:31 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 22:42:48 GMT]]></title><description><![CDATA[<p>Hmm ich seh schon, es gibt viel zu lernen. Zeit habe ich ja <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 />
Ich lerne das momentan privat und investiere ca 8 Stunden / Woche in c++.</p>
<p>@mani66<br />
Ist es schlecht new in der main zu haben?<br />
void geht doch auch, da meine main-Methode nichts als Rückgabewert erwartet, dachte ich.</p>
<p>@ der tobi<br />
Ok, in die von dir genannten Stichworte muss ich mich noch einlesen.<br />
Warum ist denn new gefährlich?<br />
Ist das nicht das gleiche:</p>
<pre><code class="language-cpp">Testobject testobj;
</code></pre>
<p>wie</p>
<pre><code class="language-cli">Testobject *testobj = new Testobject
</code></pre>
<p>Ich meine damit folgendes:<br />
Beides erzeugt doch ein Objekt im Speicher.<br />
Bei erstem greift man so auf methoden zu :</p>
<pre><code class="language-cpp">testobj.testMethode();
</code></pre>
<p>beim anderen so:</p>
<pre><code class="language-cpp">testobj-&gt;testMethode()
</code></pre>
<p>@f-th<br />
Aber würde die Headerdatei denn ohne using namespace std; funktionieren? Weil ich verwende ja string in der Headerdatei und braucht die nicht das namespace?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2267067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267067</guid><dc:creator><![CDATA[Kenan]]></dc:creator><pubDate>Sat, 03 Nov 2012 22:42:48 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 22:58:35 GMT]]></title><description><![CDATA[<p>Kenan schrieb:</p>
<blockquote>
<p>Ist es schlecht new in der main zu haben?</p>
</blockquote>
<p>Es ist schlecht <code>new</code> zu verwenden ohne zu verstehen was es ist und was es tut.</p>
<p>Kenan schrieb:</p>
<blockquote>
<p>void geht doch auch, da meine main-Methode nichts als Rückgabewert erwartet, dachte ich.</p>
</blockquote>
<p>Die Funktion <code>main()</code> gibt laut Standard einen <code>int</code> zurück. Gibt sie per <code>return</code> nichts zurück so wird implizit <code>0</code> zurückgegeben.</p>
<p>Kenan schrieb:</p>
<blockquote>
<p>Warum ist denn new gefährlich?<br />
Ist das nicht das gleiche:</p>
<pre><code class="language-cpp">Testobject testobj;
</code></pre>
<p>wie</p>
<pre><code class="language-cpp">Testobject *testobj = new Testobject
</code></pre>
<p>Ich meine damit folgendes:<br />
Beides erzeugt doch ein Objekt im Speicher.</p>
</blockquote>
<p>Die Frage ist nur, in <em>welchem</em> Speicher. Variablendeklarationen legen die Variablen die Variable auf den Stack. So deklarierte <em>automatische</em> Variablen haben eine festgelegte Lebensdauer. Mit <code>new</code> wird Speicher auf dem Heap reserviert, der solange lebt, bis er mit <code>delete</code> wieder freigegeben wird.</p>
<p>Kenan schrieb:</p>
<blockquote>
<p>Bei erstem greift man so auf methoden zu :</p>
<pre><code class="language-cpp">testobj.testMethode();
</code></pre>
<p>beim anderen so:</p>
<pre><code class="language-cpp">testobj-&gt;testMethode()
</code></pre>
</blockquote>
<p>Hat mit dem Verständnis von automatischen Variablen vs. Pointer auf objekte am Heap nur am Rande zu tun.</p>
<pre><code class="language-cpp">struct foo_t { void func() {} };

int main()
{
    foo_t foo;
    foo_t *bar = &amp;foo;

    bar-&gt;func();
}
</code></pre>
<p>... ich sehe da kein <code>new</code> .</p>
<p>Kenan schrieb:</p>
<blockquote>
<p>Aber würde die Headerdatei denn ohne using namespace std; funktionieren? Weil ich verwende ja string in der Headerdatei und braucht die nicht das namespace?</p>
</blockquote>
<pre><code class="language-cpp">#ifndef GAESTEBUCH_H
#define GAESTEBUCH_H

// #include &lt;iostream&gt; für diesen Header unnötig.
#include &lt;string&gt;

class Gaestebuch{
    public:
        Gaestebuch();
        ~Gaestebuch();

    private:
        bool checkInputs(std::string name, std::string entry);

};

#endif // GAESTEBUCH_H
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2267074</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267074</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Sat, 03 Nov 2012 22:58:35 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sat, 03 Nov 2012 23:35:38 GMT]]></title><description><![CDATA[<p>Gegenvorschlag:</p>
<p>tools.h</p>
<pre><code class="language-cpp">#ifndef TOOLS_H_INCLUDED
#define TOOLS_H_INCLUDED TOOLS_H_INCLUDED

#include &lt;iostream&gt;

void clear( std::istream &amp;is );

#endif /* TOOLS_H_INCLUDED */
</code></pre>
<p>tools.cpp</p>
<pre><code class="language-cpp">#include &quot;tools.h&quot;

#include &lt;limits&gt;

void clear( std::istream &amp;is )
{
	is.clear();
	is.ignore( std::numeric_limits&lt;std::streamsize&gt;::max(), '\n' );
}
</code></pre>
<p>entry.h</p>
<pre><code class="language-cpp">#ifndef ENTRY_H_INCLUDED
#define ENTRY_H_INCLUDED ENTRY_H_INCLUDED

#include &lt;string&gt;

class entry_t {

	friend std::istream&amp; operator&gt;&gt; ( std::istream &amp;is, entry_t &amp;entry );
	friend std::ostream&amp; operator&lt;&lt; ( std::ostream &amp;os, entry_t const &amp;entry );
	friend std::ifstream&amp; operator&gt;&gt; ( std::ifstream &amp;is, entry_t &amp;entry );
	friend std::ofstream&amp; operator&lt;&lt; ( std::ofstream &amp;os, entry_t const &amp;entry );

	private:
		std::string name;
		std::string message;
};

#endif /* ENTRY_H_INCLUDED */
</code></pre>
<p>entry.cpp</p>
<pre><code class="language-cpp">#include &quot;entry.h&quot;

#include &lt;iostream&gt;
#include &lt;fstream&gt;

#include &quot;tools.h&quot;

std::istream&amp; operator&gt;&gt; ( std::istream &amp;is, entry_t &amp;entry )
{
	std::cout &lt;&lt; &quot;Name:    &quot;;
	clear( is );
	std::getline( is, entry.name );
	std::cout &lt;&lt; &quot;Message: &quot;;
	std::getline( is, entry.message );
	return is;
}

std::ostream&amp; operator&lt;&lt; ( std::ostream &amp;os, entry_t const &amp;entry )
{
	os	&lt;&lt; &quot;Name:    &quot; &lt;&lt; entry.name &lt;&lt; '\n'
		&lt;&lt; &quot;Message: &quot; &lt;&lt; entry.message &lt;&lt; '\n';
	return os;
}

std::ifstream&amp; operator&gt;&gt; ( std::ifstream &amp;is, entry_t &amp;entry )
{
	std::getline( is, entry.name );
	std::getline( is, entry.message );
	return is;
}

std::ofstream&amp; operator&lt;&lt; ( std::ofstream &amp;os, entry_t const &amp;entry )
{
	os	&lt;&lt; entry.name &lt;&lt; '\n'
		&lt;&lt; entry.message &lt;&lt; '\n';
	return os;
}
</code></pre>
<p>guestbook.h</p>
<pre><code class="language-cpp">#ifndef GUESTBOOK_H_INCLUDED
#define GUESTBOOK_H_INCLUDED GUESTBOOK_H_INCLUDED

#include &lt;vector&gt;
#include &lt;string&gt;

#include &quot;entry.h&quot;

class guestbook_t
{
	friend std::ostream&amp; operator&lt;&lt; ( std::ostream&amp; os, guestbook_t const &amp;gb );

	private:
		std::string const filename;
		std::vector&lt; entry_t &gt; entries;

	public:
		guestbook_t( std::string const &amp;filename );
		void add_entry( entry_t const &amp;entry );
		void save();
};

#endif /* GUESTBOOK_H_INCLUDED */
</code></pre>
<p>guestbook.cpp</p>
<pre><code class="language-cpp">#include &quot;guestbook.h&quot;

#include &lt;exception&gt;
#include &lt;fstream&gt;

guestbook_t::guestbook_t( std::string const &amp;filename )
	: filename( filename )
{
	std::ifstream file( filename );
	if( !file.is_open() ) throw std::runtime_error(
		std::string( std::string( &quot;Error: The file \&quot;&quot; ) + filename + &quot;\&quot; could not be opened!\n&quot; ).c_str() );

	entry_t current_entry;

	while( file &gt;&gt; current_entry ) {
		entries.push_back( current_entry );
	}
}

void guestbook_t::add_entry( entry_t const &amp;entry )
{
	entries.push_back( entry );
}

void guestbook_t::save()
{
	std::ofstream file( filename, std::ios::trunc );

	if( !file.is_open() ) throw std::runtime_error(
		std::string( std::string( &quot;Error: The file \&quot;&quot; ) + filename + &quot;\&quot; could not be opened!\n&quot; ).c_str() );

	for( auto it = entries.begin(); it != entries.end(); ++it )
		file &lt;&lt; *it;
}

std::ostream&amp; operator&lt;&lt; ( std::ostream&amp; os, guestbook_t const &amp;gb )
{
	for( auto it = gb.entries.begin(); it != gb.entries.end(); ++it )
		os &lt;&lt; *it &lt;&lt; '\n';
	return os;
}
</code></pre>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &quot;tools.h&quot;
#include &quot;guestbook.h&quot;

int main()
{
	char const * guestbook_filename = &quot;guestbook.txt&quot;;

	try {
		guestbook_t guestbook( guestbook_filename );
		int unsigned choice = 0;

		do {
			std::cout &lt;&lt; &quot;[1] view entries\n[2] new entry\n[3] save to file\n[4] exit\n&quot;;

			while( !( std::cin &gt;&gt; choice ) || ( choice &lt; 1 || choice &gt; 4 ) ) {

				clear( std::cin );
				std::cerr &lt;&lt; &quot;Invalid Input!\n&quot;;
			}

			switch( choice ) {

				case 1:
					std::cout &lt;&lt; guestbook &lt;&lt; '\n';
					break;

				case 2: {
					entry_t entry;
					std::cin &gt;&gt; entry;
					guestbook.add_entry( entry );
					break;
				}

				case 3:
					guestbook.save();
					break;

				case 4:
					break;
			}

		} while( choice != 4 );

	} catch( std::exception &amp;e ) {

		std::cerr &lt;&lt; e.what();
		return EXIT_FAILURE;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2267081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267081</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Sat, 03 Nov 2012 23:35:38 GMT</pubDate></item><item><title><![CDATA[Reply to Erstes kleines Konsolenprogramm zum Bewerten on Sun, 04 Nov 2012 07:54:43 GMT]]></title><description><![CDATA[<p>hey swordfish, das ist echt nett von dir, dass<br />
du dir die zeit genommen hast, den Code zu verbessern.<br />
Ich denke an deiner Verbesserung kann ich noch ne Menge<br />
lernen.<br />
Ich studiere mal den Code nun Zeile für Zeile durch und<br />
falls Fragen auftauchen rühre ich mich <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2267104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267104</guid><dc:creator><![CDATA[Kenan]]></dc:creator><pubDate>Sun, 04 Nov 2012 07:54:43 GMT</pubDate></item></channel></rss>