How to convert a std::string to L data type

Viewed 605

Hello I start studying c++ and I'm trying to learn what data type is something that starts with a L, like

auto something = L"Monday";

What data type is auto? And how do I convert a std::string to this data type?

std::string my_string = "Hello World"; to ? something = L"Hello World"

1 Answers

auto is not a data-type. It is a placeholder that gets deduced depending on the initializer used.

In your case, the initializer is a wide string-literal of type const wchar_t[size], which decays to const wchar_t* when used to initialize the variable.

A wide string can be stored in a std::wstring.

How to convert a std::string (a narrow string) to a wide string depends on the source's character encoding.

Anyway, there are many others who asked that too:

C++ Convert string (or char*) to wstring (or wchar_t*)

Related