#包括在C / C绝对路径++语法 [英] #include absolute path syntax in c/c++

查看:165
本文介绍了#包括在C / C绝对路径++语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,我需要使用的#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.


  1. 的#includeD:\\ TEMP \\ temp_lib \\ temp.h

  2. 的#includeD:\\\\ \\\\温度\\\\ temp_lib temp.h

  3. 的#includeD:/temp/temp_lib/temp.h

  1. #include "D:\temp\temp_lib\temp.h"
  2. #include "D:\\temp\\temp_lib\\temp.h"
  3. #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,请参阅Where不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是

Where q-char is

源代码字符集,除了换行字符的任何成员
  和

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

在特别 \\ 并没有特殊的含义。在Q-字符序列的跨pretation是实现定义的。

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

这篇关于#包括在C / C绝对路径++语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆