C++ - ifstream not liking relative paths

2019-07-30 03:50发布

问题:

I have been having trouble with opening files with ifstream

if I do:

ifstream myfile;
    myfile.open("C:/Users/build/windows/Debug/map1.xml");

it works fine, but if I do a relative path (the executable is in Debug/)

ifstream myfile;
    myfile.open("map1.xml");

It will not find the file. Any help? Am I missing something silly?

回答1:

Most likely, your IDE changes your program's working directory when launching it. Try putting map1.xml into c:\users\build\windows



标签: c++ ifstream