ifstream question

This is a discussion on ifstream question within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Dave_Sinkula
SOP, often. Perhpas something like this:
You have your source in one directory. It builds the ...

You have your source in one directory. It builds the relocatable object files into a subdirectory (often), and places the resulting executable there as well. When it runs the executable, it runs it from where the "project directory" is (maybe not where the executable was put, and which may be different from where the source code is).

Happens all the time.

Drives you mad sometimes.

The short version is to run the code from an actual command shell.

Kind of makes sense. Thanks, mucho for that.

Still not sure why the original wouldn't run without the absolute path. But. Eh, well. New one works like a charm. Maybe I borked something elsewhere in the code.

In other words, don't be deluded into thinking that relative paths have even the faintest relation to where the executable actually is. There is, in fact, no standard way of finding out where the executable is.

Relative paths are always in relation to the current working directory, which is freely adjustable: by links to the program, by calling from a specific directory in the shell, by passing the right parameters to CreateProcess.

Each exe during run has a "current directory" which may not be the directory where the exe is located.

IDe should have a possibility to specify the "Current directory"

Have you tried to create a file instead of reading from the existing file and see where the file is created with the specified name in each case (when running from the IDE and from the prompt). In most cases the location - where file is created is the location where your exe looks for file to be opened.