Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

#include absolute path syntax in c/c++

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

Is using #include "D:empemp_libemp.h" acceptable?

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

  1. #include "D:empemp_libemp.h"
  2. #include "D:\temp\temp_lib\temp.h"
  3. #include "D:/temp/temp_lib/temp.h"

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.

I was expecting #1 to be an error during compilation, but I did not get any. Anyone has any idea why that is?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:empemp_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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...