使用 fstream需要usingnamespacestd;。。要判断是否打开成功可以这样。。fstreamfilestr;filestr.open("test.txt");if(filestr.is_open()){filestr<<"Filesuccessfullyopen";filestr.close();}else{cout<<"Erroropeningfile";}