I am learning C++ and have encountered troubles trying to read data from a file into my program. The program is meant to read an integer value from a text file and print it to the screen. It prints a number to the screen, but it is definitely not the one from the file (12 v. -1880995964). I using XCode version 2.3 with Mac OS 10.4.6. I have tried various methods, but assume that I am creating a new file, selecting "Empty File in Project" and naming it "input.txt". My code is as follows:
There is nothing in the text file except for the number "12". I appreciate any help that you can give!
Robert
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int num;
ifstream inData;
inData.open("input.txt");
inData >> num;
cout << num;
return 0;
}
There is nothing in the text file except for the number "12". I appreciate any help that you can give!
Robert