fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7. template <class T>
  8. void convertFromString(T &, const std::string &);
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. std::string s("140.127.34.222");
  13. cout << "IP Address: " << s << endl;
  14.  
  15. int a = 0;
  16. convertFromString(a,s);
  17. std::cout << a << std::endl;
  18. cout << a << endl;
  19.  
  20. system("PAUSE");
  21. return EXIT_SUCCESS;
  22. }
  23.  
  24. template <class T>
  25. void convertFromString(T &value, const std::string &s)
  26. {
  27. std::stringstream ss(s);
  28. ss >> value ;
  29. }
Success #stdin #stdout 0.02s 5268KB
stdin
Standard input is empty
stdout
IP Address: 140.127.34.222
140
140