How to use std :: wstring with std :: istringstream?

I am trying to write a template function that will extract the value of a given data type from a given string. I came up with something like this:

   template<class T>
    static T getValue(const CString& val_in)
    {
        std::wstring value = val_in;
        std::istringstream iss;
        iss.str(value);

        T val = T();
        iss>>val;
        return val;
    }

But this gives the following error for the operator iss.str(value).

error C2664: 'void std :: basic_istringstream <_Elem, _Traits, _Alloc> :: str (Const std :: basic_string <_Elem, _Traits, _Ax> &)': cannot convert parameter 1 from 'std :: wstring' to ' const stand :: basic_string <_Elem, _Traits, _Ax> & amp; ''

In principle, std::istringstreamaccepts only std::string. I thought it might be std::wistringstream, but it doesn't seem to be available. Any clues how can I do this?

+3
1

wistringstream - , :

typedef basic_istringstream<wchar_t> wistringstream;

+5

Source: https://habr.com/ru/post/1723872/


All Articles