This throws my program into an infinite loop.
Code:ofstream out;
string fName;
out.close( );
while( !out ) {
cout<<"Enter file name: ";
cin>>fName;
out.open( fName.c_str( ), ios::out | ios::binary );
}
Printable View
This throws my program into an infinite loop.
Code:ofstream out;
string fName;
out.close( );
while( !out ) {
cout<<"Enter file name: ";
cin>>fName;
out.open( fName.c_str( ), ios::out | ios::binary );
}
You expected something different? What were you expecting it to do?
gg
It's supposed to ask the user for a filename until it is able to open the file for binary output.
Oh, well, that makes sense :).
Whenever any of the error bits get set, the are not unset by an open(). You have to do it yourself. Throw an "out.clear()" at the top of your while loop.
gg
Thanks. Works now.