在尝试将整数值插入字符串时,我认为当我找到 std::to_string 时我的祈祷得到了回应,但出于某种原因,每当我实际尝试使用它时,Visual Studio 都会抱怨模棱两可。这是我的功能的当前化身:
string get_time_remaining (int elapsed)
{
string remaining;
string temp_string;
int time_remaining = TimeLimit - elapsed;
int temp_int;
temp_int = int(time_remaining / 3600);
if(temp_int == 0)
remaining = "00 : ";
else
{
temp_string = std::to_string(temp_int); // Here!
remaining = temp_string + " : ";
}
temp_int = time_remaining % 60 + 1;
if(temp_int < 10)
remaining = remaining + "0";
temp_string = std::to_string(temp_int);
remaining = remaining + temp_string;
return remaining;
}
我尝试在 to_string 的调用中转换 temp_int,如您所见,我什至尝试转换应该是整数除法的结果,但无论我做什么,VS 都会向我吐出这个:
d:\my programs\powerplay\powerplay\powerplay.cpp(1285): error C2668: 'std::to_string' : ambiguous call to overloaded function
1> d:\microsoft visual studio 10.0\vc\include\string(688): could be 'std::string std::to_string(long double)'
1> d:\microsoft visual studio 10.0\vc\include\string(680): or 'std::string std::to_string(_ULonglong)'
1> d:\microsoft visual studio 10.0\vc\include\string(672): or 'std::string std::to_string(_Longlong)'
任何帮助,将不胜感激。