What is the difference between #import and #include in C++? [duplicate]
Possible Duplicate:
C++ includ开发者_开发技巧e and import difference
Can someone explain the difference and where may I use one versus the other?
#include
includes a file in the current compilation unit.#import
does not exist in the C++ standard.
This answer was true in '14. However, the C++ standard has evolved since then and import
now exists. Without the #
.
#include
cause the referenced file to be "copy-and-pasted" at the current position during the preprocessing phase.
#import
is not in the C++
standard, but is an extension provided by some compiler. There is no consensus about what it does. For GCC, it is equivalent to #include
but try to ensure that the file has not already been included. For MSVC, it may have another meaning.
It is best to avoid #import
(sadly) if you want to write code portable to multiple compilers.
#import
imports information (types, functions, variables etc) from .lib file. It's non-standard directive.#include
includes header file.
See these topics:
- #import Directive (C/C++)
- #include Directive (C/C++)
精彩评论