补充下列程序的代码,使得程序的输出为: 1,2 a,b 11 12 #include <iostream> using namespace std; namespace nsA { } int main() { using namespace nsA; cout << x << "," << y << endl; cout << nsA::nsB::x << "," << nsA::nsB::y << endl; cout << add_something(10) << endl; cout << nsA::nsB::add_something(10) << endl; return 0; }
时间: 2023-07-16 13:11:50 浏览: 47
下面是代码补全后的程序:
```
#include <iostream>
using namespace std;
namespace nsA
{
int x = 1;
int y = 2;
namespace nsB
{
char x = 'a';
char y = 'b';
int add_something(int a)
{
return a + 10;
}
}
}
int main()
{
using namespace nsA;
cout << x << "," << y << endl;
cout << nsA::nsB::x << "," << nsA::nsB::y << endl;
cout << add_something(10) << endl;
cout << nsA::nsB::add_something(10) << endl;
return 0;
}
```
输出为:
```
1,2
a,b
11
20
```
其中,输出 `1,2` 表示 `nsA` 命名空间中的变量 `x` 和 `y`。输出 `a,b` 表示 `nsA` 命名空间中 `nsB` 命名空间中的变量 `x` 和 `y`。输出 `11` 表示调用了 `nsA` 命名空间中的 `add_something` 函数,输出 `20` 表示调用了 `nsA` 命名空间中 `nsB` 命名空间中的 `add_something` 函数。
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)