c++ namespace and include

1. Namespace in C++ namespace_51CTO Blog_Namespace in C++
 

2、

C++ #include<string> 和 using std::string

C++ #include<string> and using std::string_yang20141109's blog - CSDN Blog

C++ introduces namespaces. When using a class, you must specify the class in which space. On this issue, the string class belongs to the standard library space std, so you must declare the string class in which space to use

//Not only need to add header files, it is different from C language

#include <utils/Errors.h>

//还要加using
using android::status_t;
using android::INVALID_OPERATION;
using android::NO_ERROR;
using android::BAD_VALUE;

3. The difference between c and c++

Namespaces.

The C++ programming language was born in 1985 . The draft of the STL standard library was only formed in 1992 . There was a full seven years between the two .

The C++ Standard Library introduces a large number of new names. If these names existed when the C++ language was born, then C++ code writers would hardly use these names to define their own identifiers.

C++, why do you need using namespace std when you have include<iostream>?

An example is as follows: I have the identifier endl provided by the iostream library, so in theory, after include<iostream>, endl can be used normally.

But the reality is that endl cannot be used directly, but std::endl.

C++, why do you need using namespace std when you have include<iostream>?

An example is as follows: I have the identifier endl provided by the iostream library, so in theory, after include<iostream>, endl can be used normally.

But the reality is that endl cannot be used directly, but std::endl.

Using namespace std is just to simplify the writing of std::endl to endl. You can also achieve the same effect by using std::endl.

One concept you need to understand is:

endl and std::endl are not necessarily the same thing, and they may not even be the same thing.

This is why C++ programmers always like to bring namespaces when discussing standard library facilities on forums.

Guess you like

Origin blog.csdn.net/luyao3038/article/details/130262674