C++ Primer 3rd Edition 说
fstream 已经包含了 iostream, 可是,明显不是这么回事。
下面的代码就编不过。(VC2005)
//#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::endl;
using std::fstream;
void test_fstream(){
fstream f;
f.open("c:\\in.txt", fstream::in);
if( f.fail() ){
cout << "Can't open file for input."<<endl;
}
else{
cout << "File opened." << endl;
}
f.close();
}
int main(){
test_fstream();
return 0;
}