Generation

generate functionThu, 26 Jan 2023

how to convert the last 2 chars in a string to an int

int convert(string s){ int result = 0; for (int i = s.size() - 2; i < s.size(); i++) { result = result * 10 + s[i] - '0'; } return result; } int main() { string s = "abc123"; cout<<convert(s)<<endl; return 0; }

Want to kickstart your project?Use the new AI Studio to create your code