【发布时间】:2017-07-12 23:41:03
【问题描述】:
所有,
我正在使用 MSVC 2010,但主题有问题。
使用以下代码:
int GetValue() {return m_int;};
std::wstring temp += std::to_wstring( GetValue() );
给出一个错误:
ambiguous call to overloaded function
1> c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string(771): could be 'std::wstring std::to_wstring(long double)'
1> c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string(762): or 'std::wstring std::to_wstring(_ULonglong)'
1> c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string(753): or 'std::wstring std::to_wstring(_Longlong)'
1> while trying to match the argument list '(int)'
使用以下代码:
ostringstream ostr;
ostr << GetValue();
std::wstring temp += ostr.str();
给出以下错误:
error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)
我哪里错了?
谢谢。
【问题讨论】:
-
我很确定第一种情况是编译器/标准库错误;这应该工作
-
这可能不是编译器/库错误。在 ASCII 字符转换到宽字符转换之间没有隐式转换是有原因的。或者一串窄个字符到一串宽个字符。
-
如果你试图追加到一个现有的字符串,为什么你在那一行有类型声明?这声明了一个新变量。
-
您应该尝试更新版本的 VC++。由于
std::to_wstring是在C++11中加入的,所以VC2010支持不完整也就不足为奇了。 -
@BenVoigt,自动补全确实在 IDE 中显示了他的功能。
标签: c++ visual-studio-2010 wstring