Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences among including <xstring>, <cstring>, <string> and <wstring> in C++

Tags:

c++

include

I have seen the following #include directives:

#include <xstring>

#include <cstring>

#include <string>

#include <wstring>

What are the differences among these include directives? Did I miss any others that should be considered part of this group?

like image 639
sivabudh Avatar asked Mar 10 '10 17:03

sivabudh


1 Answers

<string> is where std::string is defined.

<xstring> is a Microsoft C++ header containing the actual implementation of the std::basic_string template. You never need to include <xstring> yourself. <string> includes it for the basic_string implementation.

<cstring> is the standard C string library (strcpy, strcat, etc) placed into the C++ std namespace.

wstring is not a header file that I'm aware of. std::wstring is the wchar_t version of std::string and is defined when including <string>.

like image 177
jmucchiello Avatar answered Oct 27 '22 16:10

jmucchiello