c++ 文件读写简单示例

#include
#include

using namespace std;

int main()
{
 char writefile[] = "hi CSDN";
 char readfile[100] = "/0";
 int nLen = strlen(writefile);

 //打开/创建文件
 ofstream ofs("filetest.txt");
 //读取文件内容
 ifstream ifs("filetest.txt");

 ofs.write(writefile, nLen);
 
 //将缓存中的数据清除,并输出直至定目的地
 ofs.flush();

 ofs.close();

 ifs.read(readfile, 100);

 cout << "readfile = " << readfile << endl;


 return 0;

你可能感兴趣的:(c++,c++,iostream,include)