fstream

I was following a tutorial online and when I ran the program, it showed differently, as if it was reading from my code lines instead of the numbers.txt file. The code does compile.

I'm thinking the problem might be because he is using Visual Studio and I'm compiling with Cygwin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	ifstream inFile;
	inFile.open("numbers.txt");
	
	
	int x, y;
	
	inFile >> x >> y;
	
	cout << "Num1: " << x << endl;
	cout << "Num2: " << y << endl;
	
	return 0;
	
}
	
Last edited on
Probably your application couldn't find the numbers.txt file.
Check inFile.is_open().
Topic archived. No new replies allowed.