4
votes

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?

1
What makes you think that there isn't a wistringstream available? See 27.7 [lib.string.streams]. - CB Bailey
@Charles, I got a compiler error (on VC9) when I tried wistringstream, let me try that again. - Naveen
Oops..compiling now, not sure what I changed other than this.. - Naveen

1 Answers

8
votes

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

typedef basic_istringstream<wchar_t> wistringstream;