使用的是vs2017
代码如下
#include "stdafx.h"
#include
#include
using namespace std;
int main()
{
int a[10];
ofstream outfile;
outfile.open("D:\d.txt",ofstream::binary|ofstream::app);
if (!outfile) {
cout << "失败" << endl;
}
cout << "请输入10个数" << endl;
for (int i = 0; i < 10; i++) {
cin >> a[i];
outfile.write((char *)&a[i], sizeof(a[i]));
}
outfile.close();
ifstream infile;
infile.open("D:\\d.txt",ifstream::binary|ifstream::in);
if (!infile) {
cout << "失败" << endl;
return 1;
}
cout << "读出文件中的数据并显示" << endl;
for (int i = 0; i < 10; i++) {
infile.read((char *)&a[i], sizeof(a[i]));
cout << a[i] << " ";
}
infile.close();
return 0;
}
文件提前建立了,路径也没问题,网上书上也各种查找了,emmmmmm。。。