当前位置: 代码迷 >> 综合 >> C++, 想要使用string ,必须要用命名空间 std
  详细解决方案

C++, 想要使用string ,必须要用命名空间 std

热度:55   发布时间:2024-01-19 15:32:55.0

 这样写就是错的,编译通不过
#include <string>
void main()
{
 string x;
}

改成这样就 OK:
#include <string>
using namespace std;
void main()
{
 string x;
} 

或者这样:
#include <string>

void main()
{
 std::string x;
} 

原因 就是 string 是标准库,C++标准引入了命名空间namespace,标准库的空间是std

  相关解决方案