Generation

generate functionThu, 26 Jan 2023

how to convert the last 3 characters on a string into an int

int stringToInt(string str) { int result = 0; for (int i = str.length()-3; i < str.length(); i++) { result = result + (str[i]-'0') * pow(10, str.length()-1-i); } return result; }

Questions about programming?Chat with your personal AI assistant