编写C++程序时,写入文件是怎样弄的?

来源:百度知道 编辑:UC知道 时间:2024/05/10 05:19:45
包括格式,例子。谢谢!!!!!!!
cbk808 :先谢谢你,学到一点,可以举一个简单的例子吗,越简单越好,必须包含格式。之后再采纳你的答案,呵呵。
谢谢!!!
c++例子,越简单越好,第二位仁兄的不大懂

#include<fstream>//这个要有
#include<string>
using namespace std;
void main()
{
string a="中国abc";
ofstream outfile("c:\\haha.txt");//定义文件输出流对象and初始化
outfile<<a<<endl;//向文件haha.txt写入字符串a
outfile.close();//关闭文件
}
//就是这样了吧,我懂得也不多,编译运行一下,然后到C盘下看看有没,更多的操作还是看书吧

#include "iostream"
#include "fstream"
#include "cstdlib"

using namespace std;

int main()
{
fstream file;
file.open("Example.txt",ios::out);
file<<"Hello World!";
file.close();
system("pause");
return EXIT_SUCCESS;
}