What is the difference between usage and inclusion in C ++?

I know that include refers to classes and is used for some built-in files, such as the std namespace ... When you include something, you can create objects and play with them, but when you use something, then you can use some kind of built-in functions. But then, how should I create my own “library” that I could “use”?

+5
source share
2 answers

Just set the #includepre-compiler to simply copy and paste the contents of the header file that was included in the current translation block. It is evaluated by the preliminary compiler.

For now using directive, the compiler directs to transfer symbol names from another scope to the current scope. This essentially acts as a compiler.

But how should I create my own “library” that I could “use”?

Namespaces are what are used to prevent character name conflicts. And usually, each library developer will have their own functionality wrapped in one or more namespaces.

+4
source

'include' basically copies-pastes the file value into the location of the include line. This is used to make your source code (usually a .c file) aware of another source code declaration (usually located in a .h file).

'using' , - ( ), :

:

std::string a;
std::string b;
std::string c;

:

using namespace std;
string a;
string b;
string c;
+2

All Articles