In attempting to insert integer values into a string, I thought that my prayers were answered when I found std::to_string, but for some reason whenever I actually try to use it, Visual Studio complains about ambiguity. Here is the current incarnation of my function:
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;
}
I have tried casting temp_int inside the call to to_string, and as you can see I even tried casting the result of what should be integer division, but no matter what I do, VS spits this out at me:
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)'
Any help would be appreciated.
MSVC11 lacks the proper overloads for std::to_string
so you have to do a static_cast
to unsigned long long
or long long
Note that this bug is fixed in the November CTP 2012. Which you can get here.
temp_int
is a int
value, and Visual Studio seems to detect only overloads which receive either double
, long long
or unsigned long long
values, so it doesn't know which overload to use, thus the ambiguity (although it would seem intuitive to cast integer to long values)
Either declare temp_int
as a long long
, or cast it when invoking the function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With