<?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[Programm lädt Daten nicht mittels ifstream aus]]></title><description><![CDATA[<p>Hallo, ich versteh einfach nicht was ich falsch gemacht habe.. folgendes Programm hab ich geschrieben:</p>
<pre><code class="language-cpp">/* 	Speicher und Lade Funktion in C++
	Variablen in externer Datei Speichern und Auslesen

*/

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

using namespace std;

int main(){

	//Variablen
	int abfrage = 0;
	int zahl1 = 0;
	int zahl = 6;

	while (abfrage!=3){

		cout &lt;&lt; &quot;Zum Laden die 1 und zum Eingeben die 2 eingeben. (Beenden = 3)&quot;;
		cin&gt;&gt;abfrage;

		if(abfrage==2){
		//SPEICHERFUNKTION

			ofstream ladspe(&quot;storev.sav&quot;);
			if (ladspe.is_open())
			{

				//Abspeichern von &quot;storev.sav&quot; 
				//Wenn keine &quot;storev.sav&quot; vorhanden, wird diese erstellt
				cout&lt;&lt;&quot;Geben Sie eine Zahl zum Speichern ein:&quot;&lt;&lt;endl;
				cin&gt;&gt;zahl1;
				zahl = zahl1;
				cout&lt;&lt;&quot;Es wurde die Variabel gespeichert&quot;&lt;&lt;endl;
				ladspe &lt;&lt; zahl;
				ladspe.close();
			};
		};

		if(abfrage==1){
		//LADEFUNKTION
			ifstream ladspe(&quot;storev.sav&quot;);
			if(ladspe.is_open())
			{
				//AUSLESEN VON top1 AUS &quot;storev.sav&quot; UND SPEICHERN IN zahl
				zahl = 0;
				ladspe&gt;&gt;zahl;
				cout&lt;&lt;&quot;Diese Variabel wurde geladen: &quot; &lt;&lt; zahl &lt;&lt; endl;
				ladspe.close();
			};
		};
	};

}
</code></pre>
<p>Compiler Error:</p>
<pre><code>manuh@manuh-desktop:~/Dokumente/Programmieren/C++$ g++ geld.cpp -o geld
geld.cpp:12: Fehler: »::main« muss »int« zurückgeben
geld.cpp: In function »int main()«:
geld.cpp:22: Fehler: Variable »std::ifstream cinsert« hat Initialisierung, aber unvollständigen Typ
</code></pre>
<p>Wäre sehr dankbar um Hilfe und Erklärung!</p>
<p>Gruß<br />
Manuh</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/247497/programm-lädt-daten-nicht-mittels-ifstream-aus</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 13:13:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/247497.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Aug 2009 19:06:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Tue, 11 Aug 2009 19:06:13 GMT]]></title><description><![CDATA[<p>Hallo, ich versteh einfach nicht was ich falsch gemacht habe.. folgendes Programm hab ich geschrieben:</p>
<pre><code class="language-cpp">/* 	Speicher und Lade Funktion in C++
	Variablen in externer Datei Speichern und Auslesen

*/

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

using namespace std;

int main(){

	//Variablen
	int abfrage = 0;
	int zahl1 = 0;
	int zahl = 6;

	while (abfrage!=3){

		cout &lt;&lt; &quot;Zum Laden die 1 und zum Eingeben die 2 eingeben. (Beenden = 3)&quot;;
		cin&gt;&gt;abfrage;

		if(abfrage==2){
		//SPEICHERFUNKTION

			ofstream ladspe(&quot;storev.sav&quot;);
			if (ladspe.is_open())
			{

				//Abspeichern von &quot;storev.sav&quot; 
				//Wenn keine &quot;storev.sav&quot; vorhanden, wird diese erstellt
				cout&lt;&lt;&quot;Geben Sie eine Zahl zum Speichern ein:&quot;&lt;&lt;endl;
				cin&gt;&gt;zahl1;
				zahl = zahl1;
				cout&lt;&lt;&quot;Es wurde die Variabel gespeichert&quot;&lt;&lt;endl;
				ladspe &lt;&lt; zahl;
				ladspe.close();
			};
		};

		if(abfrage==1){
		//LADEFUNKTION
			ifstream ladspe(&quot;storev.sav&quot;);
			if(ladspe.is_open())
			{
				//AUSLESEN VON top1 AUS &quot;storev.sav&quot; UND SPEICHERN IN zahl
				zahl = 0;
				ladspe&gt;&gt;zahl;
				cout&lt;&lt;&quot;Diese Variabel wurde geladen: &quot; &lt;&lt; zahl &lt;&lt; endl;
				ladspe.close();
			};
		};
	};

}
</code></pre>
<p>Compiler Error:</p>
<pre><code>manuh@manuh-desktop:~/Dokumente/Programmieren/C++$ g++ geld.cpp -o geld
geld.cpp:12: Fehler: »::main« muss »int« zurückgeben
geld.cpp: In function »int main()«:
geld.cpp:22: Fehler: Variable »std::ifstream cinsert« hat Initialisierung, aber unvollständigen Typ
</code></pre>
<p>Wäre sehr dankbar um Hilfe und Erklärung!</p>
<p>Gruß<br />
Manuh</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759056</guid><dc:creator><![CDATA[Manuh]]></dc:creator><pubDate>Tue, 11 Aug 2009 19:06:13 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Tue, 11 Aug 2009 19:07:30 GMT]]></title><description><![CDATA[<p>Ooops!!! Kann leider nicht editieren -.-</p>
<p>Das war das Beispielprogramm welches Funktioniert!!!</p>
<p>In meinem Programm:</p>
<pre><code class="language-cpp">/* 	Geldverwaltung Version 0.1
	by Manuel Schwarz

	letzte Änderungen: 06. Aug. */

#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

using namespace std;

int main(){
	//Variablen
	int eingabe;

	int guthaben = 2;
	float einzahlung=guthaben;
	float auszahlung;
	//Menü
	cout&lt;&lt;&quot;Geldverwaltung - Version 0.1&quot;&lt;&lt;endl; 
	cout&lt;&lt;&quot;Made by: Manuel Schwarz&quot;&lt;&lt;endl&lt;&lt;endl&lt;&lt;endl;
	ifstream cinsert(&quot;storev.sav&quot;);
			if(cinsert.is_open())
			{

				cinsert&gt;&gt;guthaben;
				cout&lt;&lt;&quot;Diese Variabel wurde geladen: &quot; &lt;&lt; guthaben&lt;&lt; endl;
				cinsert.close();
			};

	while(eingabe!=5){
	cout&lt;&lt;&quot;Auswahl:&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;1. Einzahlung&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;2. Auszahlung&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;3. Berechnung&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;4. Kontostand anzeigen&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;5. Programm beenden&quot;&lt;&lt;endl&lt;&lt;endl;

	cout&lt;&lt;&quot;Bitte geben Sie die zutreffende Nummer ein:&quot;;
	cin&gt;&gt;eingabe;

	//Einzahlung
	if(eingabe==1){

	cout&lt;&lt;&quot;\n\n	Einzahlung&quot;&lt;&lt;endl&lt;&lt;endl;
	cout&lt;&lt;&quot;Ihr Aktuelles Guthaben betraegt: &quot;&lt;&lt;guthaben&lt;&lt;&quot; EUR.&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;Wie viel Geld soll eingezahlt werden?&quot;&lt;&lt;endl;
		cin&gt;&gt;einzahlung;  
		guthaben+=einzahlung;

	cout&lt;&lt;&quot;\n\nEinzahlung erfolg! Ihr Guthaben betraegt nun: &quot;&lt;&lt;guthaben&lt;&lt;&quot; EUR.&quot;&lt;&lt;endl;
	main();
	}

	//Auszahlung
	if(eingabe==2){
	cout&lt;&lt;&quot;\n\n	Auszahlung&quot;&lt;&lt;endl;	
	main();
	}

	//Berechnung
	if(eingabe==3){
	cout&lt;&lt;&quot;\n\n	Berechnung&quot;&lt;&lt;endl;	
	main();	
	}

	//Kontostand anzeigen
	if(eingabe==4){
	cout&lt;&lt;&quot;\n\n	Kontostand anzeigen&quot;&lt;&lt;endl;	
	cout&lt;&lt;&quot;Ihr Aktuelles Guthaben betraegt: &quot;&lt;&lt;guthaben&lt;&lt;&quot; EUR.&quot;&lt;&lt;endl;
	main();
	}
}

}
</code></pre>
<p>funkitoniert es nicht!</p>
<p>Bitte editieren.</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759057</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759057</guid><dc:creator><![CDATA[Manuh]]></dc:creator><pubDate>Tue, 11 Aug 2009 19:07:30 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Tue, 11 Aug 2009 19:18:07 GMT]]></title><description><![CDATA[<p>Du hast den Header &lt;fstream&gt; vergessen.</p>
<p>Es sieht nicht so aus, als ob du stdio.h und stdlib.h benutzen würdest. die beiden sind ohnehin veraltet.</p>
<p>Du solltest/darfst nicht einfach so main() in sich selbst aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759061</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 11 Aug 2009 19:18:07 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 08:20:36 GMT]]></title><description><![CDATA[<p>Vielen Dank! <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>Aber wie könnte ich das Menü nach erfolgreichem Nutzen eines Menüpunktes wieder aufrufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759234</guid><dc:creator><![CDATA[Manuh]]></dc:creator><pubDate>Wed, 12 Aug 2009 08:20:36 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 09:14:47 GMT]]></title><description><![CDATA[<p>Manuh schrieb:</p>
<blockquote>
<p>Vielen Dank! <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>Aber wie könnte ich das Menü nach erfolgreichem Nutzen eines Menüpunktes wieder aufrufen?</p>
</blockquote>
<p>Mit Schleifen.<br />
Du solltest dir wirklich einmal ein ordentliches Buch und/oder Tutorial für Anfänger vornehmen, da werden solche Dinge alle behandelt. Ein wenig zu experimentieren ist zwar durchaus gut um das gelernte zu vertiefen, aber mit Dingen zu experimentieren die du noch nicht behandelt hast, heißt, im Trüben zu fischen udn führt zu nichts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759278</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 12 Aug 2009 09:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 09:28:58 GMT]]></title><description><![CDATA[<p>danke, ich bin auch gerade an einem Tutorial dran. Jedoch kam mir dann dieses Programm als Idee, und ich denke dass ich damit viele Sachen besser verstehe. Habe jetzt noch ein Problem..</p>
<p>Mein Programm:</p>
<pre><code class="language-cpp">/* 	Geldverwaltung Version 0.1
	by Manuel Schwarz

	letzte Änderungen: 06. Aug. */

#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;fstream&gt;

using namespace std;

int main(){
	//Variablen
	int eingabe=0;

	float guthaben;
	float auszahlung;
	//DATEN EINLESEN
	ifstream cinsert(&quot;cdata.sav&quot;);
			if(cinsert.is_open())
			{

				guthaben = 0;
				cinsert&gt;&gt;guthaben;

				cinsert.close();
			};

	//Menü
	while(eingabe!=5){
	system(&quot;clear&quot;);
	cout&lt;&lt;&quot;Geldverwaltung - Version 0.1&quot;&lt;&lt;endl; 
	cout&lt;&lt;&quot;Made by: Manuel Schwarz&quot;&lt;&lt;endl&lt;&lt;endl&lt;&lt;endl;

	cout&lt;&lt;&quot;Auswahl:&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;1. Einzahlung&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;2. Auszahlung&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;3. Berechnung&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;4. Kontostand anzeigen&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;5. Programm beenden&quot;&lt;&lt;endl&lt;&lt;endl;

	cout&lt;&lt;&quot;Bitte geben Sie die zutreffende Nummer ein:&quot;;
	cin&gt;&gt;eingabe;

	//Einzahlung
	if(eingabe==1){
		system(&quot;clear&quot;);
	cout&lt;&lt;&quot;\n\n	Einzahlung&quot;&lt;&lt;endl&lt;&lt;endl;
	cout&lt;&lt;&quot;Ihr Aktuelles Guthaben betraegt: &quot;&lt;&lt;guthaben&lt;&lt;&quot; EUR.&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;Wie viel Geld soll eingezahlt werden?&quot;&lt;&lt;endl;
		cin&gt;&gt;einzahlung;  
		guthaben+=einzahlung;

	//Speichern
		ofstream cinsert(&quot;cdata.sav&quot;);
			if (cinsert.is_open())
			{
				cinsert&lt;&lt; guthaben;
				cinsert.close();
			};

	cout&lt;&lt;&quot;\n\nEinzahlung erfolg! Ihr Guthaben betraegt nun: &quot;&lt;&lt;guthaben&lt;&lt;&quot; EUR.&quot;&lt;&lt;endl;
	main();
	}

	//Auszahlung
	if(eingabe==2){
	system(&quot;clear&quot;);
	cout&lt;&lt;&quot;\n\n	Auszahlung&quot;&lt;&lt;endl;	

	}

	//Berechnung
	if(eingabe==3){
	system(&quot;clear&quot;);
	cout&lt;&lt;&quot;\n\n	Berechnung&quot;&lt;&lt;endl;	

	}

	//Kontostand anzeigen
	if(eingabe==4){
	system(&quot;clear&quot;);
	cout&lt;&lt;&quot;\n\n	Kontostand anzeigen&quot;&lt;&lt;endl;	
	cout&lt;&lt;&quot;Ihr Aktuelles Guthaben betraegt: &quot;&lt;&lt;guthaben&lt;&lt;&quot; EUR.&quot;&lt;&lt;endl;

	}
	}
	if(eingabe==5){
	system(&quot;exit&quot;);
	}

}
</code></pre>
<p>Ich kann aber irgendwie keine 2 3 und 4 eingeben. Dann wird die Zahl gelöscht und da steht weiterhin: &quot;Bitte geben Sie die zutreffende Nummer ein:&quot;</p>
<p>Wieso?</p>
<p>Danke nochmal</p>
<p>Gruß<br />
Manuh</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759302</guid><dc:creator><![CDATA[Manuh]]></dc:creator><pubDate>Wed, 12 Aug 2009 09:28:58 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 09:54:04 GMT]]></title><description><![CDATA[<p>Manuh schrieb:</p>
<blockquote>
<p>Ich kann aber irgendwie keine 2 3 und 4 eingeben. Dann wird die Zahl gelöscht und da steht weiterhin: &quot;Bitte geben Sie die zutreffende Nummer ein:&quot;</p>
<p>Wieso?</p>
</blockquote>
<p>Weil dein Programm den Bildschirm löscht, dann die gewünschte Ausgabe macht, dann den Bildschirm wieder löscht und das Menü wieder hinmalt. das ganze geht so schnell das du es nicht siehst.</p>
<p>Ansonsten solltest du dringend pumuckls Ratschläge befolgen. Außerdem ist von der Benutzung von system generell abzuraten, ganz besonders system(&quot;exit&quot;) - da gibt es sogar einen eigenen C++ Befehl für.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759328</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 12 Aug 2009 09:54:04 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 10:49:19 GMT]]></title><description><![CDATA[<p>Ein gutes Deutsches Tutorial:</p>
<p><a href="http://www.cpp-tutor.de/cpp/hinweise.html" rel="nofollow">http://www.cpp-tutor.de/cpp/hinweise.html</a></p>
<pre><code class="language-cpp">if(eingabe==5){ 
    system(&quot;exit&quot;); 
    }

ersetzt mal system(&quot;exit&quot;);  mit: return 0;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1759362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759362</guid><dc:creator><![CDATA[sup]]></dc:creator><pubDate>Wed, 12 Aug 2009 10:49:19 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 14:10:55 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Du solltest/darfst nicht einfach so main() in sich selbst aufrufen.</p>
</blockquote>
<p>Weil ?<br />
EDIT: Hoffentlich hat niemand auf den Link geklickt, der war nicht zu diesem Thema ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759521</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759521</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Wed, 12 Aug 2009 14:10:55 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 14:16:16 GMT]]></title><description><![CDATA[<p>Tim06TR schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Du solltest/darfst nicht einfach so main() in sich selbst aufrufen.</p>
</blockquote>
<p>Weil ?</p>
</blockquote>
<p>1. Weil es vom Standard her verboten ist.<br />
2. Weil es hier überhaupt keinen Sinn macht. Der Stackoverflow kommt mit Sicherheit, einfach durch die normale Benutzung des Programmes.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759529</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Wed, 12 Aug 2009 14:16:16 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 14:23:15 GMT]]></title><description><![CDATA[<p>Tim06TR schrieb:</p>
<blockquote>
<p>Weil ?</p>
</blockquote>
<p>Weil is so:</p>
<p>Der böse, böse Standard, §3.6.1,3 schrieb:</p>
<blockquote>
<p>The function main shall not be used (3.2) within a program. The linkage (3.5) of main is implementation-defined. A program that declares main to be inline or static is ill-formed. The name main is not otherwise reserved.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1759531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759531</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 12 Aug 2009 14:23:15 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 14:53:41 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Tim06TR schrieb:</p>
<blockquote>
<p>Weil ?</p>
</blockquote>
<p>Weil is so:</p>
<p>Der böse, böse Standard, §3.6.1,3 schrieb:</p>
<blockquote>
<p>The function main shall not be used (3.2) within a program. The linkage (3.5) of main is implementation-defined. A program that declares main to be inline or static is ill-formed. The name main is not otherwise reserved.</p>
</blockquote>
</blockquote>
<p>Was übrigens noch interessant zu wissen ist: In ANSI C ist es tatsächlich erlaubt, main rekursiv aufzurufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759558</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 12 Aug 2009 14:53:41 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 17:23:55 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Was übrigens noch interessant zu wissen ist: In ANSI C ist es tatsächlich erlaubt, main rekursiv aufzurufen.</p>
</blockquote>
<p>Macht es dort mehr Sinn? Ein rekursiver <code>main()</code> -Aufruf sollte so gut wie immer durch eine Schleife ersetzbar sein. Im Notfall gibts ja noch <code>goto</code> ... <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/1759668</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759668</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 12 Aug 2009 17:23:55 GMT</pubDate></item><item><title><![CDATA[Reply to Programm lädt Daten nicht mittels ifstream aus on Wed, 12 Aug 2009 18:13:15 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Was übrigens noch interessant zu wissen ist: In ANSI C ist es tatsächlich erlaubt, main rekursiv aufzurufen.</p>
</blockquote>
<p>Macht es dort mehr Sinn? Ein rekursiver <code>main()</code> -Aufruf sollte so gut wie immer durch eine Schleife ersetzbar sein. Im Notfall gibts ja noch <code>goto</code> ... <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>
</blockquote>
<p>Sinn kann ich nicht erkennen, es ist nur nicht verboten. Interssehalber habe ich's mal mit der klassischen Anwendung für Rekursion versucht:</p>
<p>faculty.c</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

int main(int argc, char * argv[]){
	if (argc&gt;=2){
		int i = atoi(argv[1]);
		if (i&gt;0){
			sprintf(argv[1],&quot;%d&quot;,i-1);
			return i*main(argc,argv);
			}
		else
			return 1;
	}
}
</code></pre>
<p>Gibt die Fakultät des ersten Kommandozeilenarguments als Fehlercode zurück. Hätte man natürlich auch ganz einfach in eine Unterfunktion packen können, sehr sinnvoll ist es daher nicht.</p>
<p>(Entschuldigung für mein wahrscheinlich sehr schlechtes C - ich benutze es normalerweise nicht)</p>
<p>edit: Und wie ich sehe funktioniert es bei mir nur bis 5 richtig. Ob das jetzt ein Programmfehler ist oder eine Beschränkung meiner Shell mag ich nicht testen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1759685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1759685</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 12 Aug 2009 18:13:15 GMT</pubDate></item></channel></rss>