#include c/c++中的绝对路径语法

#include absolute path syntax in c/c++(#include c/c++中的绝对路径语法)

本文介绍了#include 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"?

我已经尝试了这些不同的用法,并且似乎都有效.

I have tried these different usage and it all seems to work.

  1. #include "D: emp emp_lib emp.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: 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++中的绝对路径语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:#include c/c++中的绝对路径语法