c++蔡鸟问题

来源:百度知道 编辑:UC知道 时间:2024/06/11 19:38:29
文件I/O(iostream.h,assert.h)怎么用??
回答格式
1、基本方法函数介绍,最好加个简单例子
2、一段完整的操作实例代码
一经采用本人严重感谢,会追加分的(20)。
一定要有点中文解释
第一位帅哥的叫我怎么看得懂

网上有代码或看本书
代码我以发到你邮箱了

#include <fstream.h>
#include <iostream.h>
#include <assert.h>

int main()
{
int n, v;
ofstream fout("output.dat");
if(!fout)
{
cerr<<"Can't open file output.dat"<<endl;
return 1;
}
cout<<"Enter a number:"<<endl;
cin>>n;
assert(n>0);
for(int i = 0; i < n; ++i)
{
cout<<"Enter a value:"<<endl;
cin>>v;
fout<<v<<endl;
}
fout.close();
return 0;
}