E
ehui928
The following program is used to open a file in mode both read and
append, but it has
a problem that the file can't be opened.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
// open in both input and append mode
fstream inOut("copy.out", ios_base::in|ios_base::app);
//fstream inOut("copy.out", ios_base::in);
if (!inOut)
{
cerr << "failed to open file!" << endl;
exit(1);
}
// do something with inOut
inOut.close()
return 0;
}
When I compile and run it, the result says "failed to open file!" .
But if I change to the commend line which only contain mode
ios_base::in,then
file can be opened successfully.
Why dose this happen? I wonder whether ios_base::in can't use with
ios_base::app together? But it does work in BS's book.
Can any one give me some help?
append, but it has
a problem that the file can't be opened.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
// open in both input and append mode
fstream inOut("copy.out", ios_base::in|ios_base::app);
//fstream inOut("copy.out", ios_base::in);
if (!inOut)
{
cerr << "failed to open file!" << endl;
exit(1);
}
// do something with inOut
inOut.close()
return 0;
}
When I compile and run it, the result says "failed to open file!" .
But if I change to the commend line which only contain mode
ios_base::in,then
file can be opened successfully.
Why dose this happen? I wonder whether ios_base::in can't use with
ios_base::app together? But it does work in BS's book.
Can any one give me some help?