Converting string to int


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include <sstream>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string s = "-123";
  9.  
  10. int i;
  11. bool success;
  12. istringstream myStream(s);
  13.  
  14. if (myStream>>i)
  15. success = true;
  16. else
  17. success = false;
  18.  
  19. std::cout << success << std::endl;
  20. std::cout << i << std::endl;
  21. }

URL: http://www.techbytes.ca/techbyte99.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.