Got a little file problem..

I read about how to input/output data from a file to a program. Then I decided to experiment it with easy codes n stuff. But my program won't work...I don't know what I did wrong here...I wrote the number 500 in a notepad and saved it as Num.txt

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
#include<iostream>
#include<fstream>

using namespace std;

int main()
{
	ifstream inputFile;
	int number;
	inputFile.open("Num.txt");

	if (inputFile)
	{
		while (inputFile >> number)
		{
			cout << number << endl;
		}
		inputFile.close();
	}
	else
	{
		cout << "file didn't open" << endl;
	}

	return 0;
}


it doesn't output what I wrote in the file Num.txt but only "file didn't open" message.
You probably saved the file in the wrong location. The program looks for the file Num.txt in the working directory of the program.

http://en.wikipedia.org/wiki/Working_directory
Topic archived. No new replies allowed.