Dec 5, 2004 #1 Tdrgabi Programmer Joined Jun 24, 2004 Messages 43 Location RO hi ... i need an urgent answer to a problem ... i have a lot of numerical values ... into strings (stl string). i need to convert it to "int" because i want to do some math stuff with them .... so how can i convert string ------->>> int ?
hi ... i need an urgent answer to a problem ... i have a lot of numerical values ... into strings (stl string). i need to convert it to "int" because i want to do some math stuff with them .... so how can i convert string ------->>> int ?
Dec 5, 2004 1 #2 ArkM IS-IT--Management Joined Oct 21, 2002 Messages 1,819 Location RU Use old good atoi() from C/C++ library: Code: #include <cstdlib> #include <string> ... string s = "12345"; int i = atoi(s.c_str()); // c_str() string member function. c_str() returns a pointer to C-like representation (with zero terminator) of a stl::string object... Upvote 0 Downvote
Use old good atoi() from C/C++ library: Code: #include <cstdlib> #include <string> ... string s = "12345"; int i = atoi(s.c_str()); // c_str() string member function. c_str() returns a pointer to C-like representation (with zero terminator) of a stl::string object...
Dec 6, 2004 #3 uolj Programmer Joined Jul 2, 2003 Messages 529 Location GB Or stringstreams: Code: #include <sstream> #include <string> ... std::string s("12345 5.23 7"); std::istringstream istr(s); int i, j; double d; istr >> i >> d >> j; Upvote 0 Downvote
Or stringstreams: Code: #include <sstream> #include <string> ... std::string s("12345 5.23 7"); std::istringstream istr(s); int i, j; double d; istr >> i >> d >> j;