C++中包含<xstring>,<cstring>,<string>和<wstring>之间的差异

siv*_*udh 15 c++ include

我看过以下#include指令:

#include <xstring>

#include <cstring>

#include <string>

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

这些包含指令有何不同?我是否错过了其他应被视为该群体一部分的人?

jmu*_*llo 18

<string>在这里std::string被定义.

<xstring>是一个Microsoft C++标头,包含std::basic_string模板的实际实现.你永远不需要包括<xstring>自己.<string>包括它的basic_string实施.

<cstring>是放置在C++ 名称空间中的标准C字符串库(strcpy,strcat等)std.

wstring不是我知道的头文件.std::wstring是包含的wchar_t版本std::string和定义<string>.


Joh*_*itb 16

只有<cstring><string>是标准标题.<xstring>是一个非标准的标题.

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

这是<string.h>,但声明放入命名空间std.它是C头的"C++版本".

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

std::string是定义的地方.它与C头无关.