I am trying to load the content of a file using the following code. The file has 3 words in each line. The code should read the file and output each line. Please let me know what I am doing wrong here.
If I moved things around a bit it worked for me.
I was taught your functions should be first. (30 years ago) Main should be last.
When you compile a program just like when you run a program, things at the top happen first. If main needs a value, and it's not part of main, it should be above it.
Modern compilers may not care and it may not be taught that way anymore but when it doesn't work the new way try the old way ;P
I also did not have file_p.h which is not used in this program anyway.
I was taught your functions should be first. (30 years ago) Main should be last.
I normally prefer main() to be first. Of course this means that you will need function prototypes before main() which is good thing since it makes using multiple files easier. Function prototypes would go into an include file and the implementations would go into the various implementation files.
I also did not have file_p.h which is not used in this program anyway.
Are you sure? It might provide the prototypes for the functions which would make moving the functions before main() unnecessary.
Thank you very much for the prompt replies, everyone! As Thomas rightly pointed out, the problem was related to the opening of the file correctly. The "file.txt" was in the "src" folder of my Eclipse project directory. Therefore, modifying "file.txt" to "src/file.txt" while creating the "ifstream" instance resolved the problem.
While it is a side-issue for this thread, I do agree with SamualAdams about the wonky ordering C programmers have been taught to use. Of course, I am still a fan of Pascal...