tags:

views:

458

answers:

1

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  A: 

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

typedef basic_istringstream<wchar_t> wistringstream;

Lou Franco
yes, it is there..I think there was an error somewhere else and I got confused.
Naveen