Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

stream

stl

I am trying to write a template function which will extract the value of the given datatype from the 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 iss.str(value) statement.

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 std::basic_string<_Elem,_Traits,_Ax> &'

So basically, std::istringstream is accepting only std::string . I thought there may be a std::wistringstream but there doesn't seem to be one available. Any clues how can I do it?

like image 263
Naveen Avatar asked Feb 28 '23 00:02

Naveen


1 Answers

My compiler has wistringstream -- this is all it is:

typedef basic_istringstream<wchar_t> wistringstream;

like image 140
Lou Franco Avatar answered Mar 07 '23 07:03

Lou Franco