Reputation: 173
I don't know why this is not compiling.
std::wstring number = std::to_wstring((long long)another_number);
Compiler : gcc 5.1.0
IDE : codeblocks 17.12
Upvotes: 3
Views: 3948
Reputation: 173
Workaround
std::string temp = std::to_string((long long)number);
std::wstring number_w(temp.begin(), temp.end());
Upvotes: 0
Reputation: 48297
you have to ensure that:
you have included the string header:
#include <string>
you are compiling with c++11 flag: -std=c++11
$ g++ -std=c++11 your_file.cpp -o your_program
here is the official doc https://en.cppreference.com/w/cpp/string/basic_string/to_wstring
----and ofcourse, i hope you mean something like
std::wstring number = std::to_wstring((long long)anotherNumber);
instead of
std::wstring number = std::to_wstring((long long)number);
coz you cant declare number and initialize it with a another variable named number...
this example here is working fine:
#include <iostream>
#include <string>
int main() {
auto numberX{2020};
std::wstring f_str = std::to_wstring((long long)numberX);
std::wcout << f_str;
return 0;
}
Upvotes: 4