Search code examples
c++includepython-import

Understanding Preprocessor Directives in C++ as a beginner


I recently began learning C++. As a programmer coming from Python, I've noticed some general similarities when it comes to how certain things in C++ do the same thing over in Python.

One question I had is understanding Preprocessor directives. I/O Stream seems to be a common one to use in beginner programs.

Is #include effectively the same thing as import in Python, or is it completely different than importing "modules"?


Solution

  • C++ did not have modules until the latest standard (C++20). #include is not the same as import in the languages that support modules. Instead, it is a source code - level inclusion of a "header" file. Usually, the headers only contain declarations but not definitions of what you are "importing". The definitions are contained in compiled libraries that are added by the linker.