对于一个存在着标准输入输出的C++控制台程序,一般会在#include <iostream>的下一行发现一句话,using namespace std。
这句话其实就表示了所有的标准库函数都在标准命名空间std中进行了定义。其作用就在于避免发生重命名的问题。
#include <iostream> using namespace std; namespace ZhangSan { int a=10; //张三把10赋值给了变量a } namespace LiSi { int a=5; //李四把10赋值给了变量a } void main() { int a=1; cout<<"张三定义的a="<<ZhangSan::a<<endl; cout<<"李四定义的a="<<LiSi::a<<endl; cout<<"主函数定义的a="<<a<<endl; }
上例中的“ZhangSan::a”和“LiSi::a”分别表示了调用张三命名空间中的a变量和李四命名空间中的a变量。这样的好处显而易见,那就是虽然张三和李四这两个程序员都定义了一个变量a,但是并不会出现重名的危险。
2. 关于using namespace *
std::cout |
#include <iostream> using namespace std; namespace ZhangSan { int a=10; //张三把10赋值给了变量a } namespace LiSi { int a=5; //李四把10赋值给了变量a } void main() { int a=1; using namespace ZhangSan; using namespace LiSi; cout<<a<<endl; }
#include <iostream> using namespace std; namespace ZhangSan { int a=10; //张三把10赋值给了变量a } namespace LiSi { int a=5; //李四把10赋值给了变量a } void main() { using namespace ZhangSan; using namespace LiSi; cout<<a<<endl; }
十一月 | ||||||
---|---|---|---|---|---|---|
日 | 一 | 二 | 三 | 四 | 五 | 六 |
27 | 28 | 29 | 30 | 31 | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
2022年8月22日 02:15
There are several public and private schools in Punjab that are associated with this board; all of these schools operate under its supervision and are also controlled by it. Many students from this state took the class 11th exams this year as well, and they are all currently waiting for the Punjab +1 PSEB 11th Question Paper 2023 of these exams. Punjab +1 Model Paper 2023 Punjab Board will as soon as possible announce the Punjab +1 Important Question Paper 2023 for class 11th via their official website. Numerous pupils took the class 11th exams that were administered by this board in the previous academic year, which was done in the past. In this test, girls performed better than guys.
2023年1月25日 18:48
Congratulations on taking the first step to learning C++! If you are a beginner in the world of programming, C++ can be a great place to start. As one of the oldest and most popular programming languages, C++ has many advantages real property management Elkhart County that make it perfect for those just starting out. Its syntax is relatively easy to understand, and its massive library of resources makes it a great platform for advancing your coding skills. With the help of the ACM, you will have access to a number of resources to help you on your journey to becoming a C++ programmer. Good luck!