How can i ensure that 1024 is an integer? thank you....
Code:#include <iostream> #include <string> #include <sstream> using namespace std; int main(void){ int age; string buf("1024"); stringstream(buf) >> age; cout << age << ".\n"; return 0; }
This is a discussion on confirm that the result of stringstream is integer. within the C++ Programming forums, part of the General Programming Boards category; How can i ensure that 1024 is an integer? thank you.... Code: #include <iostream> #include <string> #include <sstream> using namespace ...
How can i ensure that 1024 is an integer? thank you....
Code:#include <iostream> #include <string> #include <sstream> using namespace std; int main(void){ int age; string buf("1024"); stringstream(buf) >> age; cout << age << ".\n"; return 0; }
Check the state of the stream after the extraction. Typical method:
Code:std::stringstream sstr(buf); if (sstr >> age) // Extraction OK if (!(sstr >> age)) // Extraction not OK
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^