using namespace std
时间: 2023-10-16 15:11:04 浏览: 85
C++中的using namespace std
The "using namespace std" statement in C++ allows you to use all the names in the "std" namespace, which is the namespace for the standard library. This means you can use names like "cout" and "cin" without having to specify the namespace, for example:
```
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
int x;
cin >> x;
return 0;
}
```
Without the "using namespace std" statement, you would have to qualify the names with the namespace, like this:
```
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
int x;
std::cin >> x;
return 0;
}
```
While this may not seem like a big deal for a small program like this, it can be very tedious and error-prone for larger programs that use many names from the standard library.
阅读全文