The C++ code below does int
to string
and a string
to int
conversions. Then, it repeats these steps again. The stringst
I'm a C guy most of the day, so I would simply use atoi()
do to the conversion:
#include // header for atoi()
//stream1 >> i3; // replace this for the line below
i3 = atoi(stream1.str().c_str());
cout << "i3-- " << i3 << endl;
What I'm doing is retrieving a std::string
from the stringstream
, and from that, getting a const char*
to be used as argument for atoi()
, which converts a C string to an integer.