Sorry if this topic has been posted a million times over, but I’m having some problems getting a character (that’s a number) into an int. And by that, I want the actual numeric value, not the ASCII value which is what I keep getting. Is there a simple, standard way to do this in C++?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <string>
int getCredits(std::string);
int main()
{
std::string testString = "1234";
std::cout << getCredits(testString) << std::endl; //outputs '50'
return 0;
}
int getCredits(std::string s)
{
returnstatic_cast<int>(s.at(1));
}