更新时间:2021-12-21 06:33:46
c>有一个转换构造函数接受
const char *
( CStringT :: CStringT
)将 std :: string
转换为 CString
的过程非常简单:
CString
has a conversion constructor taking a const char*
(CStringT::CStringT
). Converting a std::string
to a CString
is as simple as:
std::string stdstr("foo");
CString cstr(stdstr.c_str());
这适用于UNICODE和MBCS项目。如果 std :: string
包含嵌入的 NUL
字符,那么必须使用具有长度参数的转换构造函数: p>
This works for both UNICODE and MBCS projects. If your std::string
contains embedded NUL
characters you have to use a conversion constructor with a length argument:
std::string stdstr("foo");
stdstr += '\0';
stdstr += "bar";
CString cstr(stdstr.c_str(), stdstr.length());