* * * * 打开文件的方法(一)举例 #includefstream using namespace std; void fn() { ofstream myf(mydata); if(myf.fail()) { cerrerror\n; return; } myf.....; } 例:ifstream myinf(“abc.dat”,ios::nocreate); 例:fstream myinout(“abc.dat”,ios::in|ios::out); * 打开文件的方法(二) 首先建立一个对象,在需要时再由open()函数将流对象和一个具体的文件相连 ifstream::open(char*,int=ios::in,int=filebuf::openprot) ofstream::open(char*,int=ios::out,int=filebuf::openprot) fstream::open(char*,int,int=filebuf::openprot) e.g. ofstream output; output.open(“output.dat”) * 文件关闭 void ifstream::close() void ofstream::close() void fstream::close() e.g.
原创力文档

文档评论(0)