Have you ever been confused about the different strings types?

Today, I’ve had some free time and I have been researching and gathering information. The result is this cheat sheet with information about some (all of them would be crazy) well-known string types.

C Language
  • char* : This should be null terminated. You can use encoding such as UTF-8 but generally each byte corresponds to one characters.
  • wchar_t* : Basic Unicode string type null terminated. Generally it indicates UCS2 encoding.
  • TCHAR* : A null terminated array, contains wchar_t if UNICODE is defined, otherwise uses chars.
  • LPSTR : Win32 typedef for char*.
  • LPWSTR : Win32 typedef for wchar_t*.
  • LPTSTR : Win32 typedef for TCHAR*.
  • LPCSTR, LPCWSTR, LPCTSTR : Const versions.
C++ Language
  • std::basic_string<T> : The native C++ type. This is just a template.
    • std::string : Class that contains an array of bytes. It assumes that you’re looking at ANSI here without any encoding.
    • std::wstring : Contains an array of wchar_t. UCS2 encoding is assumed.
Managed C++
  • System::String^ : I know this is not C++ but If you’re working with Managed C++ (I do), you can use this UTF-16 string.