| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 489 人关注过本帖
标题:想问一下关于文件 函数的用法。。。
只看楼主 加入收藏
龙飞
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-6-8
收藏
 问题点数:0 回复次数:0 
想问一下关于文件 函数的用法。。。
这样子是可以运行的:
#include <iostream>
#include <fstream>
using namespace std;
void f()
{ofstream outfile("text.dat",ios::trunc);
if(!outfile)
{cout<<"open error!"<<endl;
exit(1);
}
for(int i=0;i<81;i++)
outfile<<i<<" ";
// outfile.close;
}
int main()
{void f();
f();
return 0;
}
而我想要把"text.dat"换成一个变量,也就是说想要把文件变成自己想要的任意名字。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void f()
{string name;
cout<<"input the file name:";
cin>>name;
ofstream outfile(name,ios::trunc);
if(!outfile)
{cout<<"open error!"<<endl;
exit(1);
}
for(int i=0;i<81;i++)
outfile<<i<<" ";
// outfile.close;
}
int main()
{void f();
f();
return 0;
}
改完之后就没有办法编译通过了,不懂得是为什么,,
想请教一下,是否有办法实现我的这个想法,要的话,该怎么改才好?
搜索更多相关主题的帖子: 函数 用法 文件 outfile 
2007-06-11 02:30
快速回复:想问一下关于文件 函数的用法。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011328 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved