如何将 std::wstring 与 std::istringstream 一起使用?
我正在尝试编写一个模板函数,它将从给定的字符串中提取给定数据类型的值。我想出了这样的方法:
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;
}
但这会给 iss.str(value)
语句带来以下错误。
错误 C2664:'无效 std::basic_istringstream<_Elem,_Traits,_Alloc>::str(const std::basic_string<_Elem,_Traits,_Ax> &)' : 无法将参数 1 转换为 'std::wstring' 到 'const std::basic_string<_Elem,_Traits,_Ax> &'
所以基本上, std::istringstream
仅接受 std::string
。我认为可能有一个 std::wistringstream
但似乎没有可用的。有什么线索我该怎么做吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的编译器有 wistringstream —— 这就是全部:
typedef basic_istringstream; wistringstream;
My compiler has wistringstream -- this is all it is:
typedef basic_istringstream<wchar_t> wistringstream;