fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main ()
  5. {
  6. string str;
  7. cout <<"CONVERSION\n\n";
  8. cout <<"Base 11 to Decimal\n";
  9. cout << "Base 11: ";
  10. getline (std::cin,str);
  11.  
  12. const auto bad_loc = str.find_first_not_of("0123456789aA");
  13. if(bad_loc != std::string::npos) {
  14. cerr << "Invalid input\n";
  15. throw "bad input"; // or whatever handling
  16. }
  17.  
  18. unsigned long ul = std::stoul (str,nullptr,11);
  19. cout << "Decimal: " << ul << '\n';
  20. return 0;
  21. }
Success #stdin #stdout 0s 3460KB
stdin
123
stdout
CONVERSION

Base 11 to Decimal
Base 11: Decimal: 146