No suitable constructor exists to convert from char to string
-
24-10-2019 - |
Question
I have defined a createdirectory(const stdStr& path)
in a class and I am accessing that function from another class using Directory::CreateDirectory("C:\\Temp");
I am getting an error on "C"\Temp" saying that "
no suitable constructor exists to convert from "const char [4]" to "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>"
Solution
Because your "C:\\Temp"
string is an array of char
, but the function is using a string templated on wchar
. Personally, I avoid Unicode like the plague, but I think you need L"C:\\Temp"
(note the preceding L).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow