我有使用 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,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &&,_Elem *)' : 无法推导出 'std::basic_istream<_Elem, _Traits> &&' 来自 'std::ostringstream'