Frage zur Nutzung von fstream:
-
#include <fstream> #include <iostream> #include<string> using namespace std; int main() { fstream f; f.open("test.dat",ios::out); f<<"test1"<<endl; f<<"test2"<<endl; f.close(); f.open("test.dat", ios::in); char s[265]; while(!f.eof()) { f.getline(s,sizeof(s)); cout<<s<<endl; } f.close(); f.open("test.dat",ios::out|ios::app); f<<"test3"<<endl; f<<"test4"<<endl; f.close(); cout<<endl<<endl; f.open("test.dat", ios::in); while(!f.eof()) { f.getline(s,sizeof(s)); cout<<s<<endl; } f.close(); }Warum schreibt und liest das Programm nur einmal?
bobjob
-
http://fara.cs.uni-potsdam.de/~kaufmann/?page=GenCppFaqs&faq=eof#Answ
Das schon gelesen?
-
Jetzt schon ... konnte den Fehler jetzt auch beheben.