使用数组
从一个文件中读取一个整数列表
然后按读取顺序的相反顺序将元素写入另一个文件
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
const int CAPACITY = 50;
int numbers[CAPACITY];
int size=0;
ifstream inputfile;
ofstream outputfile;
//打开输入文件
inputfile.open("D:\\VS 2019\\input.txt");
if (!inputfile)
{
cout << "Error. Input filr cannot be opened." << endl;
return 0;
}
while (inputfile >> numbers[size] && size <= 50)
{
size++;
}
inputfile.close();
//打开输出文件
outputfile.open("D:\\VS 2019\\output.txt");
if (!outputfile)
{
cout << "Error. Input filr cannot be opened." << endl;
return 0;
}
for (int i = size - 1;i >= 0;i--)
{
outputfile << numbers[i] << " ";
}
outputfile.close();
return 0;
}