Playground
#include <iostream> #include <sstream> #include <vector> #include <string> using namespace std; int main() { string s; s = "1 20 3 40"; int temp; vector<int> v; istringstream is(s); while (is >> temp) v.push_back(temp); //v={1, 20, 3, 40}; ostringstream os; for (int i=0; i<(int) v.size(); i++) os << v[i]; string res = os.str(); cout << res << endl; //pechati '120340' ostringstream d; d.precision(4); d << fixed << 3.5 << " "; d << fixed << 2.01010101 << " " << 8.0; res = d.str(); cout << res << endl; //pechati '3.5000 2.0101 8.0000' return 0; }
Input data
Program output
no input
Execute
Language: ????????? | Memory: ???? KB | Time: ??? ms
Nothing has been executed, yet!