Description of the namespace std

Source: Internet
Author: User

Namespace is the namespace of c ++. In order to solve the problem that naming is easy to repeat during programming, a namespace concept is proposed. The names of variables, functions, and classes in the same namespace cannot be repeated. These names can be repeated in different namespaces. For example:
Namespace n1
{
Int;
}

Namespace n2
{
Int;
}

It can be used as follows:
N2: a = 8;
N1: a = 8;
You can also declare that the namespace I want to use is n2:
Using namespace n2;
In this case, the default namespace is n2, which can be directly written:
A = 8;
Same as n2: a = 8;

And using namespace std;
Std in is the namespace used by standard library functions. Here we should first talk about the methods that contain library functions. The old method is:
# Include <stdio. h>
This is to be compatible with c. Without namespaces, he can directly call the library functions in it, for example:
Printf ("% d", 2 );
The new method is:
# Include <cstdio>
This is to better support classes, but namespace should be used for example:
Using namespace std;
Printf ("& d", 2 );
If you do not add using namespace std ;,
In the program, the effects of std: cout, std: cin, std: endl are the same.

If the compiler supports both <iostream> and
<Iostream. h>. If # include
<Iostream>, the elements of the iostream library placed under the namespace std are obtained;
If you use # include <iostream. h>, the same elements that are placed in the global space are obtained. All
An element obtained from a local space may cause a name conflict. The original intention of designing a namespace is to avoid such a name conflict.
Occurrence of word conflict.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.