can be any of these reasons
You are not passing the name of the file while running this program
The file does not exist, or the name is misspelled
You don't have permission to open the file
also, I am not sure if it is not really opened as if(myfile) should be if (myfile.is_open())
First general debugging rule I use is that before I even check for the file being open I output the argv[] to see if I picked the right one. Then I can start figuring out if it is my other parts of the code.
Yes, you have to have the text file in the same directory as the program otherwise you have to specify the full path to the text file like JLBorges said. I added text to the file and read it in then printed it out to show it does work, but left the code from above just to show it is the same code.
It will look for the file in the working directory (the directory that you have navigated to using the cd command). If you run the program from some other directory it will not find the file, unless that directory also contain a file with the same name.
$ cd Desktop
$ ./fileOpen file.txt
File open!
$ cd ..
$ Desktop/fileOpen file.txt
File do not exist!
$ Desktop/fileOpen Desktop/file.txt
File open!