#include <iostream>
#include <fstream>
#include <cstdlib>
int main(int argc, char *argv[])
{
usingnamespace std;
char ch;
if (argc == 1)
{
cerr << "Program requires arguments, activation failed. Goodbye! \n";
}
cout << "Please enter a file name for input. Note that the program will only write your data to one file. \n";
ofstream fout(argv[1], ios_base::out | ios_base::app);
if (!fout.is_open())
{
cerr << "Could not open file, goodbye. \n.";
exit(EXIT_FAILURE);
}
while (cin.eof() == false)
{
cin >> ch;
fout << ch;
}
fout.clear();
fout.close();
ifstream fin(argv[1], ios::in);
cout << fin;
fin.close();
return 0;
}
The program compiles but fails to do its task when I run it in debugging mode. Instead of displaying input it shows numbers and exists without pausing.
Could you please point out my errors and a possible resolution? Thank you in advance!