5

Possible Duplicate:
C++ include and import difference

Can someone explain the difference and where may I use one versus the other?

Community
  • 1
  • 1
user659086
  • 91
  • 1
  • 1
  • 2

3 Answers3

6
  • #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 #.

Didier Trosset
  • 34,718
  • 13
  • 85
  • 119
4
  • #import imports information (types, functions, variables etc) from .lib file. It's non-standard directive.
  • #include includes header file.

See these topics:

Nawaz
  • 341,464
  • 111
  • 648
  • 831
4

#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.

Sylvain Defresne
  • 40,235
  • 11
  • 72
  • 82