The purpose of "import std"; in c ++

I saw the following small snippet of code on the cppdepend site.

import std; // Module import directive.
int main() 
{
    std::cout<<"Hello World\n";
}

So import std;what is the purpose in C ++? How to use import std;instead using namespace std;in C ++?

I tried to compile the program in the g ++ compiler , but I got an error.

+4
source share
1 answer

So what is the purpose of importing std; C ++?

Its purpose is to make the names of the module stdavailable. Modules are a language function that has been proposed for inclusion in the future C ++ standard.

How to use import std;instead of using namespace std;in C ++?

, . - . , .

g++, .

, , , , , .

GCC: https://gcc.gnu.org/wiki/cxx-modules .

+7

Source: https://habr.com/ru/post/1681806/


All Articles