When I run the following program it shows an error error: call of overloaded ‘stoi(int&)’ is ambiguous
Why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
usingnamespace std;
int main ()
{
int str;
cin>>str;
//String to int
int i=stoi(str);
cout<<i/2<<endl;
return 0;
}
The stoi function takes a string as its first parameter; you're passing an int as its first parameter. There is therefore no overload of the stoi function that exists which takes an int as its first parameter.
In short, you're converting an int to an int which is redundant, so there is no actual function for it.