#include absolute path syntax in c/c++

后端 未结 1 338
小鲜肉
小鲜肉 2020-12-04 02:16

For some reason, I need to use the absolute path in #include for my system.

Is using #include \"D:\\temp\\temp_lib\\temp.h\" acceptable?

相关标签:
1条回答
  • 2020-12-04 02:39

    Every implementation I'm aware of, and certainly MSVC 2005 and linux, allows you to specify the directory paths in which to find header files. You should include D:\temp\temp_lib on the list of directory paths, and then use

    #include <temp.h>
    

    For gcc, use -I path. For MSVC, see Where does Visual Studio look for C++ header files?

    The reason that #1 isn't a syntax error is that, although it looks like a string literal, it isn't. The specification is

    #include "q-char-sequence"
    

    Where q-char is

    any member of the source character set except the new-line character and "

    In particular, \ has no special meaning. The interpretation of the q-char-sequence is implementation-defined.

    0 讨论(0)
提交回复
热议问题