This is my first post, so please go easy on me .
I intend to both read from and write to a file. Can I have an ifstream and ofstream open for the same file at the same time? Or do I have to close one before I open the other?
Also, will the following code work to ensure the file I am writing to does not already exist, thus preventing overwriting?
Code:
ofstream target_out; // ofstream to write to target file
bool done = false;
char targetname[80];
while( !done ) {
cout << "Enter data target file: ";
cin >> targetname;
target_out.open( targetname, ios::nocreate );
if( target_out.is_open() ) {
cout << "The file you entered already exists." << endl;
target_out.close();
}
else
done = true;
}
target_out.open( targetname, ios::noreplace );
Thanks!