Posted By

oznek on 09/03/10


Tagged

String c conversion int


Versions (?)

Converting string to int


 / Published in: C++
 

URL: http://www.techbytes.ca/techbyte99.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. }

Report this snippet  

You need to login to post a comment.