Xcode 9.4 unable to find .txt file despite it being in the directory

I'm working on a C++ project with XCode, at one point in my code I call shader.open (m_FilePath, std::ios::in);, shader being an ifstream variable and m_FilePath a std::string in which the shader's file path is stored. Later in my code, when I call shader.fail () it return true unless I provide the full path in m_FilePath.

I already changed the project's directory to be the folder where the file resides, added the file refence to the project and to Copy Files in the target's build phases, setting the destination as "Products directory", but I'm still unable to use a relative file path.

What am I doing wrong? Currently using XCode 9.4.1 on MacOS High Sierra 10.13.6.

Why do you want to use relative paths?

I guess it should probably work, but you don't know what other code outside your control is doing to the current directory.

You need to debug this by checking what the current directory is at the point where you call open(), enumerating the directory to see what files are actually present, etc.

Xcode 9.4 unable to find .txt file despite it being in the directory
 
 
Q