input.txt文件内容
8
1.0 0.9973978 0.9896158 0.9767267 0.9588510 0.9361556 0.9088516 0.8771925 0.8414709
方案一
#include<iostream>
#include<fstream>
using namespace std;
ifstream fi("input.txt", ios::in);
int main()
{
int n;
fi >> n;
double* arr = new double[n + 1];
cout << n << endl;
for (int i = 0; i <= n; i++) {
fi >> arr[i];
}
for (int i = 0; i <= n; i++) {
cout << arr[i] << " ";
}
cout << endl;
delete[] arr;
system("pause");
return 0;
}
运行结果:
方案二:
#include<iostream>
#include<fstream>
using namespace std;
fstream fi("input.txt", ios::in);
fstream fo("output.txt", ios::out | ios::trunc);
int main()
{
cin.rdbuf(fi.rdbuf());
cout.rdbuf(fo.rdbuf());
return 0;
}