Use of c_str() for wstrings in c++

285 Views Asked by At

When I have a:

std::string s 

I can do:

s.c_str() 

to convert it to a char*. As I understand it only adds a '\0' to the end of s.

Can I then conclude that just adding '\0' converts a string to a char*? Is doing something like that converting it to char* then?

std::string s = "Hi ";
s[2] = '\0'

Does .c_str() convert all strings to their corresponding character pointer? E.g. for std::string, std::u8string, std::wstring, std::u16string, std::u32string, does c_str() convert them to char*, char8_t*, wchar_t*, char16_t*, char32_t* respectively?

0

There are 0 best solutions below