fehler in der schleife?

Ups, klappt doch nicht.
Ich habe die Abfrageschleife noch in Kommentar zeichen gehabt, hab diese jetzt rausgenommen und sofort der gleiche Fehler :mad:
 
moin


Code:
for (;;)
	{
		char Input_Sign;
		cout << "\nWenn Sie Ihre Berechnungen noch einmal aendern wollen\n";
		cout << "geben Sie J (fuer ja) ein, andernfalls N (fuer nein) ein: ";
		cin >> Input_Sign;

		if (Input_Sign == 'j')
		{
			cout<<"Ja";
		}
		if (Input_Sign == 'n')
		{
			cout<<"Nein";
			break;
		}
	}

	char Dateiname[30];
	cout <<"Bitte geben Sie einen Namen fuer Ihre Datei an...";
	cin.getline(Dateiname, 29);
	strcat(Dateiname, ".txt");

	std::ofstream Ausgabe(Dateiname);

Funktioniert nicht?


mfg
umbrasaxum
 
Nee, nur bis
cout <<"Bitte geben Sie einen Namen fuer Ihre Datei an...";

getline wird nicht angenommen. Kann das am VC 6.0 liegen?
 
moin


Eigentlich nicht.
Versuch einfach mal cin>> Dateiname; statt cin.getline(Dateiname, 29);


mfg
umbrasaxum
 
Wenn ich den Quelltext so schreibe
Code:
for (;;)
	{
		char Input_Sign;
		cout << "\nWenn Sie Ihre Berechnungen noch einmal aendern wollen\n";
		cout << "geben Sie J (fuer ja) ein, andernfalls N (fuer nein) ein: ";
		cin >> Input_Sign;

		if (Input_Sign == 'j')
		{
			cout<<"Ja";
		}
		if (Input_Sign == 'n')
		{
			cout<<"Nein";
			break;
		}
	}

	char Dateiname[30];
	cout <<"Bitte geben Sie einen Namen fuer Ihre Datei an...";
	cin.getline(Dateiname, 29);
	strcat(Dateiname, ".txt");

	std::ofstream Ausgabe(Dateiname);

und nach dem ersten cin.getline(....);
die gleich Zeile nochmal schreibe klappt es :google:

also
Code:
char Dateiname[30];
	cout <<"Bitte geben Sie einen Namen fuer Ihre Datei an...";
	cin.getline(Dateiname, 29);
                cin.getline(Dateiname, 29);

	strcat(Dateiname, ".txt");

	std::ofstream Ausgabe(Dateiname);

funktioniert das erstellen der Datei komischerweise. Weiß von euch jemand warum?

Danke erstmal an alle!

Gruss Thomas
 
moin


Aaaaa, sag das doch gleich ;)

Versuch es mal so:
Code:
char Dateiname[30];
cout <<"Bitte geben Sie einen Namen fuer Ihre Datei an...";

fflush(stdin);
cin.getline(Dateiname, 29);
strcat(Dateiname, ".txt");

std::ofstream Ausgabe(Dateiname);


mfg
umbrasaxum
 
jap, super...so fluppts sauber
jetzt muß ich mir nur nochmal irgendwo was zu fflush raussuchen......
vielen dank
 
moin


MSDN hat gesagt.:
The fflush function flushes a stream. If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream. If the stream is open for input, fflush clears the contents of the buffer. fflush negates the effect of any prior call to ungetc against stream. Also, fflush(NULL) flushes all streams opened for output. The stream remains open after the call. fflush has no effect on an unbuffered stream.

Buffers are normally maintained by the operating system, which determines the optimal time to write the data automatically to disk: when a buffer is full, when a stream is closed, or when a program terminates normally without closing the stream. The commit-to-disk feature of the run-time library lets you ensure that critical data is written directly to disk rather than to the operating-system buffers. Without rewriting an existing program, you can enable this feature by linking the program's object files with COMMODE.OBJ. In the resulting executable file, calls to _flushall write the contents of all buffers to disk. Only _flushall and fflush are affected by COMMODE.OBJ.

For information about controlling the commit-to-disk feature, see Stream I/O, fopen, and _fdopen.


mfg
umbrasaxum
 
Zurück