Issue with command line input

I'm currently using Microsoft Visual Studio C++ 2010 Express for the following exercise:

Write a program that copies your keyboard input (up to the simulated end-of-file)
to a file named on the command line.

I've set the command line arguments in the Debugging panel to to argc and argv, and wrote the following program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#include <iostream>
#include <fstream>
#include <cstdlib>


int main(int argc, char *argv[])
{
	using namespace 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!
Topic archived. No new replies allowed.