C ++ - ifstream不喜欢相对路径 [英] C++ - ifstream not liking relative paths
本文介绍了C ++ - ifstream不喜欢相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用ifstream
I have been having trouble with opening files with ifstream
打开文件时遇到问题:
ifstream myfile;
myfile.open("C:/Users/build/windows/Debug/map1.xml");
它工作正常,但如果我做一个相对路径(可执行文件在Debug /)
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?
推荐答案
很可能,您的IDE在启动时会更改程序的工作目录。尝试将 map1.xml
插入 c:\users\build\windows
Most likely, your IDE changes your program's working directory when launching it. Try putting map1.xml
into c:\users\build\windows
这篇关于C ++ - ifstream不喜欢相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文