fork download
  1. #i#include <iostream> // std::cout
  2. #include <string> // std::string, std::stoi
  3.  
  4. int main ()
  5. {
  6. std::string str_dec = "2001, A Space Odyssey";
  7. std::string str_hex = "40c3";
  8. std::string str_bin = "-10010110001";
  9. std::string str_auto = "0x7f";
  10.  
  11. std::string::size_type sz; // alias of size_t
  12.  
  13. int i_dec = std::stoi (str_dec,&sz);
  14. int i_hex = std::stoi (str_hex,nullptr,16);
  15. int i_bin = std::stoi (str_bin,nullptr,2);
  16. int i_auto = std::stoi (str_auto,nullptr,0);
  17.  
  18. std::cout << str_dec << ": " << i_dec << " and [" << str_dec.substr(sz) << "]\n";
  19. std::cout << str_hex << ": " << i_hex << '\n';
  20. std::cout << str_bin << ": " << i_bin << '\n';
  21. std::cout << str_auto << ": " << i_auto << '\n';
  22.  
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:2: error: invalid preprocessing directive #i
 #i#include <iostream>   // std::cout
  ^
prog.cpp: In function 'int main()':
prog.cpp:13:15: error: 'stoi' is not a member of 'std'
   int i_dec = std::stoi (str_dec,&sz);
               ^
prog.cpp:14:15: error: 'stoi' is not a member of 'std'
   int i_hex = std::stoi (str_hex,nullptr,16);
               ^
prog.cpp:14:34: error: 'nullptr' was not declared in this scope
   int i_hex = std::stoi (str_hex,nullptr,16);
                                  ^
prog.cpp:15:15: error: 'stoi' is not a member of 'std'
   int i_bin = std::stoi (str_bin,nullptr,2);
               ^
prog.cpp:16:16: error: 'stoi' is not a member of 'std'
   int i_auto = std::stoi (str_auto,nullptr,0);
                ^
prog.cpp:18:3: error: 'cout' is not a member of 'std'
   std::cout << str_dec << ": " << i_dec << " and [" << str_dec.substr(sz) << "]\n";
   ^
prog.cpp:19:3: error: 'cout' is not a member of 'std'
   std::cout << str_hex << ": " << i_hex << '\n';
   ^
prog.cpp:20:3: error: 'cout' is not a member of 'std'
   std::cout << str_bin << ": " << i_bin << '\n';
   ^
prog.cpp:21:3: error: 'cout' is not a member of 'std'
   std::cout << str_auto << ": " << i_auto << '\n';
   ^
stdout
Standard output is empty