istringstream

Solutions on MaxInterview for istringstream by the best coders in the world

showing results for - "istringstream"
Édouard
11 Jun 2019
1// istringstream::str
2#include <string>       // std::string
3#include <iostream>     // std::cout
4#include <sstream>      // std::istringstream
5
6int main () {
7  std::istringstream iss;
8  std::string strvalues = "32 240 2 1450";
9
10  iss.str (strvalues);
11
12  for (int n=0; n<4; n++)
13  {
14    int val;
15    iss >> val;
16    std::cout << val << '\n';
17  }
18  std::cout << "Finished writing the numbers in: ";
19  std::cout << iss.str() << '\n';
20  return 0;
21}
Federica
13 Jun 2016
1If you include #include <sstream> then you must also reference the class by:
2
3std::stringstream or declare using namespace std; before using it.