#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char buf[32] = "helloworld";
ofstream ofs("sad.txt"); //创建一个输出流对象
if(!ofs) //如果不存在这个文件报错
{
cout<<"open failure"<<endl;
}
ofs<<buf; //将buf数组里的内容写入这个文件中
ofs.close(); //关闭文件
return 0;
}
//ofstream 打开一个文件向文件里写东西,对于程序来讲是输出到文件里
//ifstream 打开一个文件从文件里读东西到程序里,对于程序来讲是输入
ofstream
最新推荐文章于 2024-05-17 15:36:52 发布