C++:std 没有成员“字符串”

tmi*_*hty 6 c++ string namespaces c++11 visual-studio-2012

我编写了以下代码:

STDMETHODIMP CWrapper::openPort(LONG* m_OpenPortResult)
{
    std::string str;
    //const char * c = str.c_str();
    // Open("test".c_str())

    return S_OK;
}
Run Code Online (Sandbox Code Playgroud)

编译器告诉我“命名空间 std 中没有这样的成员“字符串”。

我的包含看起来像这样:

#include "stdafx.h"
#include "Wrapper.h"
#include <string.h>
using namespace std;
Run Code Online (Sandbox Code Playgroud)

到目前为止我做错了什么吗?

Pet*_*r R 13

您需要添加以下内容:

#include <string>
Run Code Online (Sandbox Code Playgroud)