CamolaZ

string:: resolution scope to _type

Apr 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. // stoi example
  2. #include <iostream>   // std::cout
  3. #include <string>     // std::string, std::stoi
  4. using namespace std;
  5. int main ()
  6. {
  7.   string str_dec = "2001, A Space Odyssey";
  8.   string str_hex = "40c3";
  9.   string str_bin = "-10010110001";
  10.   string str_auto = "0x7f";
  11.  
  12.   string::size_type sz;   // alias of size_t
  13.  
  14.   int i_dec = std::stoi (str_dec,&sz);
  15.   int i_hex = std::stoi (str_hex,nullptr,16);
  16.   int i_bin = std::stoi (str_bin,nullptr,2);
  17.   int i_auto = std::stoi (str_auto,nullptr,0);
  18.  
  19.   cout << str_dec << ": " << i_dec << " and [" << str_dec.substr(sz) << "]\n";
  20.   cout << str_hex << ": " << i_hex << '\n';
  21.   cout << str_bin << ": " << i_bin << '\n';
  22.   cout << str_auto << ": " << i_auto << '\n';
  23.  
  24.   return 0;
  25. }
Add Comment
Please, Sign In to add comment