补充下列程序的代码,使得程序的输出为: 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 17:11:33 浏览: 93
使用include <iostream>时一定要加using namespace std
程序缺少了一些命名空间的定义和函数声明,以下是完整的代码:
```
#include <iostream>
namespace nsA {
int x = 1;
int y = 2;
namespace nsB {
char x = 'a';
char y = 'b';
int add_something(int a) {
return a + 10;
}
}
}
using namespace std;
using namespace nsA;
int main() {
cout << x << "," << y << endl;
cout << nsA::nsB::x << "," << nsA::nsB::y << endl;
cout << nsA::nsB::add_something(10) << endl;
cout << add_something(10) << endl;
return 0;
}
```
输出:1,2 a,b 11 12
阅读全文