问题描述
由于某些原因,我需要使用的#include
的绝对路径我的系统。
For some reason, I need to use the absolute path in #include
for my system.
中使用的#include?D:\\ TEMP \\ temp_lib \\ temp.h
接受
我曾尝试这些不同的用法,这一切似乎工作。
I have tried these different usage and it all seems to work.
-
的#includeD:\\ TEMP \\ temp_lib \\ temp.h
-
的#includeD:\\\\ \\\\温度\\\\ temp_lib temp.h
-
的#includeD:/temp/temp_lib/temp.h
#include "D:\temp\temp_lib\temp.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:的目录路径列表中\\ TEMP \\ temp_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:\temp\temp_lib on the list of directory paths, and then use
#include <temp.h>
有关GCC,使用-I的路径的。对于MSVC,请参阅
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是
Where q-char is
源代码字符集,除了换行字符的任何成员
和
在特别 \\
并没有特殊的含义。在Q-字符序列的跨pretation是实现定义的。
In particular, \
has no special meaning. The interpretation of the q-char-sequence is implementation-defined.
这篇关于#包括在C / C绝对路径++语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!