Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // stoi example
- #include <iostream> // std::cout
- #include <string> // std::string, std::stoi
- using namespace std;
- int main ()
- {
- string str_dec = "2001, A Space Odyssey";
- string str_hex = "40c3";
- string str_bin = "-10010110001";
- string str_auto = "0x7f";
- string::size_type sz; // alias of size_t
- int i_dec = std::stoi (str_dec,&sz);
- int i_hex = std::stoi (str_hex,nullptr,16);
- int i_bin = std::stoi (str_bin,nullptr,2);
- int i_auto = std::stoi (str_auto,nullptr,0);
- cout << str_dec << ": " << i_dec << " and [" << str_dec.substr(sz) << "]\n";
- cout << str_hex << ": " << i_hex << '\n';
- cout << str_bin << ": " << i_bin << '\n';
- cout << str_auto << ": " << i_auto << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement