Can not find text file

I am reading numbers from a text file. I was under the assumption that the text file needed to be saved in the same location as my cpp. file. Nothing is read from the file and when i attempt to debug, it looks like garbage in the variables. I have looked and looked and i can not understand where i need to store this txt file so that it is found and read. I have found that it needs to be stored in the same directory as the compiler, but i am unsure what that means. I am already one week late with this assignment as i am trying hard to finish it on my own, I really need some help.

Thank You

Todd
Which compiler/IDE are you using?

The input file needs to be placed in the 'working directory', but the default working directory can vary depending on your IDE.

You can always specify the full path to the file, then it does not matter where it is placed. Beware: on Windows, it is better to use the forward slash instead of backslash to separate directories.
The programmer has full control on how to open the file, including where the file is located.
Here are a few tips that might help you:

1. Put the full path of the file in your code:

1
2
3

std::string Inputfile="/home/me/myInputFile";


2. Check all return codes or statuses from all functions:

1
2
3
4
5
6
7
8

std::ifstream In( InputFile.c_str() );

if( In.is_open() )
    {
     /*    Your code to read the file    */
    }


3. Post your own code.


Good luck!
Great. Putting in the full path helped. I can read the numbers. Thank you guys.
Now if i could only figure out passing arrays in functions and how to write a proper function call.

Thanks again ...
Todd
Topic archived. No new replies allowed.