编程论坛
注册
登录
编程论坛
→
C++教室
求教 如何用C++创建一个文件并且向文件写入数据
asd6791868
发布于 2008-10-13 20:32, 4463 次点击
我刚刚接触C++才学到第2章。。。
请问
如何用C++创建一个文件并且向文件写入数据
2 回复
#2
wfx_best
2008-10-13 20:56
我给你写一个,看对吗?你要到 EXE 文件相同目录下找那个 f1.txt文件
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
char a[20];
ofstream outfile("f1.txt");
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
//cout<<"enter / if you want to break:"<<endl;
char c;
while(cin.get(c))
{
if(c=='/')break;
outfile.put(c);
}
outfile.close();
return 0;
}
#3
asd6791868
2008-10-13 22:17
请问C++程序设计课本里有这些内容么
我怎么没找到
1