Error : 'to_wstring' is not a member of 'std'

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

Answers (2)

Workaround

std::string temp = std::to_string((long long)number);
std::wstring number_w(temp.begin(), temp.end());

Upvotes: 0

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

Related Questions