I am trying to replicate an exercise from a text book, however the file never reads and so the if statement is triggered telling me that I have not read the file. I have no error message or warnings. I am sure I am missing something fundamental but I just don't know what it could be.... I am running OSX, Clang7.0, using Qt (but I have also tried this in sublime text and it fails there too)
here is the code:
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream file_reader ( "myfile.txt" );
if ( !file_reader.is_open() )
{
cout<<"Could not open file!"<<'\n';
}
int number;
file_reader >> number;
cout<<number;
}
The file is in the same directory as the program files. It is a .txt file simply containing:
12 a b c
I have tried putting the full path and had a look at some similar threads but it does not seems to be the same problem as this
Thanks for any help in advance