在程序中使用相对路径需要注意的问题

文件结构:

demo

  srcmain.cpp;Box.cpp

  includeBox.h

编译链接之后:

demo

  srcmain.cpp;Box.cpp

  includeBox.h

  binmain.exe

比如srcmain.cpp中有一句

ifstream ifs("..\include\Box.h")

那么如果你打开cmd切换到路径demo,并输入binmain.exe,你会发现程序找不到"..includeBox.h",因为此时的".."代表的是demo的上一级目录,而不是bin的上一级目录

输入cd bin,再输入main.exe,程序正常运行

原文地址:https://www.cnblogs.com/qrlozte/p/4213708.html