注册 登录
编程论坛 C++教室

新手提问,将数据写入文件没效果

岚忆汐 发布于 2013-09-07 19:36, 344 次点击
程序代码:
#include<fstream>
using namespace std;
int main()
{
    double income=123.45,expenses=987365;
    int week=7,year=2013;
    ofstream outfile("D\\a.txt",ios::out);
    outfile<<"income="<<income<<"expenses="<<expenses<<endl;
    outfile<<"week="<<week<<"year="<<year<<endl;
    outfile.close();
}[local]1[/local]
2 回复
#2
chs094122013-09-07 23:12
路径名称弄错了!
D:\\a.txt
#3
pauljames2013-09-14 07:18
ofstream outfile("D\\a.txt",ios::out);
文件操作记得判断返回值,确保文件打开成功,否则后面操作无意义
1