【发布时间】:2011-07-31 10:47:59
【问题描述】:
我有使用 lexical_cast 的模板化代码。
现在我想删除所有 lexical_cast 调用(因为它不适用于 /clr)。
我需要在 std::string 和它们的值之间转换对象。
所以,第一个方向很简单(T _from, std::string _to):
std::ostringstream os;
os << _from;
_to = os.str();
但我想不出一种从字符串到任何类型的通用方法(我需要一些可以与模板一起使用的通用方法,不能只对每种类型使用特化并使用像atoi 这样的函数)
编辑:
当然,我已经尝试在相反的方向使用 ostringstream。我收到此错误:
错误 C2784: 'std::basic_istream<_elem> &std::operator >>(std::basic_istream<_elem> &&,_Elem *)' : 无法推断出 'std::basic_istream 的模板参数<_elem> &&' 来自 'std::ostringstream'
【问题讨论】:
标签: c++ templates boost lexical-cast