有关文件的问题
#include<iostream>#include<fstream>
using namespace std;
int main()
{
fstream iofile("text.txt",ios::in|ios::out);
if(!iofile)
{
cerr<<"Cannot open file!\n";
return 1;
}
iofile<<"abcdefghij";
iofile.seekp(4,ios::beg);
iofile.put('X');
char str[10];
iofile.seekg(0,ios::beg);
iofile.get(str,10);
cout<<str<<endl;
return 0;
}
书上是输出“abcdXfghi”的,可是我在直接是“Cannot open file!”。郁闷~