/*ASCLL文件的输入/出
将十个元素键盘输入文件 并显示在屏幕上
*/
#include<fstream>
#include<iostream>
using namespace std;
void input()
{
ofstream outfile("f1.dat",ios::out);
//文件打开的两种方式 :1.open()函数 2.文件输出对象的构造函数
if(!outfile)//文件打开失败 对象返回值为0
{
cerr<<"open error!"<<endl;
exit(1);
}
int arr[10],i;
cout<<"please put into ten numbers:\n"<<e;i<10;i++)
{
cin>>arr[i]; ndl;
for(i=0;i<10;i++)
{
cin>>arr[i];
// outfile<<arr[i]<<" ";
outfile<<arr[i];//问题处:为什么不加“ ”就是地址值???
}
outfile.close();
}
void output()
{
ifstream infile("f1.dat",ios::in);
if(!infile)
{
cerr<<"to open error!"<<endl;
exit(1);
}
int arr[10],i;
for(i=0;i<10;i++)
{
infile>>arr[i];
cout<<arr[i];
}
infile.close();
}
int main()
{
input();
output();
return 0;
}
/*
1.outfile<<arr[i];//为什么不加“ ”就是地址值
显示结果:
please put into ten numbers:
1 2 3 4 5 6 7 8 9 10
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 请按任意键继续. . .
求解*/
文件内容读取显示问题
最新推荐文章于 2022-05-25 14:31:03 发布