Skip to content

Instantly share code, notes, and snippets.

@theblixguy
Created February 17, 2017 23:17
Show Gist options
  • Save theblixguy/ab02641c5a4abb677c950ef562f8562f to your computer and use it in GitHub Desktop.
Save theblixguy/ab02641c5a4abb677c950ef562f8562f to your computer and use it in GitHub Desktop.
String to Integer
#include <iostream>
#include <string>
int main() {
std::string numberString = "1234";
int numberInt = 0;
for (int i = 0; i < numberString.length(); i++) {
numberInt = numberInt * 10 + numberString[i] - '0';
}
std::cout << "String number: " << numberString << std::endl;
std::cout << "Integer number: " << numberInt << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment