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

文件结构:

demo\

  src\main.cpp;Box.cpp

  include\Box.h

 

编译链接之后:

demo\

  src\main.cpp;Box.cpp

  include\Box.h

  bin\main.exe

 

比如src\main.cpp中有一句

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

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

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

posted @ 2015-01-09 16:44  rldts  阅读(404)  评论(0编辑  收藏  举报