Everything runs except that
in the results.txt file created in the c drive the only number outputted is the number 5
how do i create a loop so the output in the result.txt file will be:
3
4
5
here is my code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int num;
ifstream inFile;
ofstream outFile;
inFile.open("data.txt");
if (! inFile)
{
cout << "ERROR - File did not open!\n";
exit(1);
}
cout << "Here are the numbers in the file: \n";
while(inFile >> num)
{
cout << num << '\n';
}
outFile.open("c:\\result.txt");
if(outFile.fail())
{
cout << "ERROR - File did not open!\n";
system("pause");
return 1; /// or return 1
}
cout << endl << endl;
outFile << num;
inFile.close();
outFile.close();
system("pause");
return 0;
}
i meant to copy the data.txt file to results.txt file