@David Thornley: Sorry, I am new to C++/programming in general. What would be the best looping statement to use? I do not know how many numbers there are.Also, I checked the file-first number is not 0, it is 42

@mokwi8: After fixing the typo, you've written a program to get exactly one integer (the first) out of the file and print it. That's exactly what your program is doing! Keep reading and your book will no doubt show you how to handle the rest of the file.

Problem 1 (the one the compiler sees) is a simple typo: inFile should be inputFile. Do make sure you check for typos like this before posting to Stack Overflow.

Problem 2: the path name to your file is probably wrong, and generally, when you try to read from a stream that couldn't be initialized properly because the file couldn't be opened, you'll get 0.

In this case the path you specified is a relative path to the file from the directory your program was launched in, so whatever directory you ran the program from would need a subdirectory called "MacintoshHD", then "Users", then... you get the idea. To get the correct path, right-click on the file in the Finder and select "Get Info". Under "Where: " you'll see the correct path to the directory that contains your file; it will probably say "/Users/moshekwiat/Desktop". Add "/random.txt" to that and that should be the path you use.

Normally, C++ programmers will write code to make sure the file opens correctly before reading from it. A simple way to check for that after initializing inputFile, but before trying to read from it is: