#include c/c++ 中的绝对路径语法 [英] #include absolute path syntax in c/c++
问题描述
出于某种原因,我需要在#include
中为我的系统使用绝对路径.
For some reason, I need to use the absolute path in #include
for my system.
使用 #include "D: emp emp_lib emp.h"
是否可以接受?
Is using #include "D: emp emp_lib emp.h"
acceptable?
我尝试了这些不同的用法,似乎都有效.
I have tried these different usage and it all seems to work.
#include "D: emp emp_lib emp.h"
#include "D:\temp\temp_lib\temp.h"
#include "D:/temp/temp_lib/temp.h"
我只想知道我应该使用哪个?我使用的是 MSVC 2005.我想知道这三个是否仍然可以在 Linux 或其他环境中工作.
I just want to know which one should I use? I am using MSVC 2005. I'm wondering if all three will still work in Linux or other environment.
我原以为 #1 是编译过程中的错误,但我没有得到任何错误.有人知道这是为什么吗?
I was expecting #1 to be an error during compilation, but I did not get any. Anyone has any idea why that is?
推荐答案
我所知道的每个实现,当然还有 MSVC 2005 和 linux,都允许您指定在其中查找头文件的目录路径.您应该在目录路径列表中包含 D: emp emp_lib,然后使用
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: emp emp_lib on the list of directory paths, and then use
#include <temp.h>
对于 gcc,使用 -I path.对于 MSVC,请参阅 Visual Studio 在哪里查找 C++ 头文件?
For gcc, use -I path. For MSVC, see Where does Visual Studio look for C++ header files?
#1 不是语法错误的原因是,虽然它看起来像一个字符串文字,但它不是.规格是
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"
q-char 在哪里
源字符集的任何成员,除了换行符和
any member of the source character set except the new-line character and "
特别是 没有特别的意义.q-char-sequence 的解释是实现定义的.
In particular, has no special meaning. The interpretation of the q-char-sequence is implementation-defined.
这篇关于#include c/c++ 中的绝对路径语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!