Q:

Use the function you wrote for the first exercise in § 8.1.2 (p. 314) to print the contents of an istringstream object

0

Use the function you wrote for the first exercise in § 8.1.2 (p. 314) to print the contents of an istringstream object.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <string>
#include <sstream>

std::istream &read(std::istream &is) {
  //auto old_state = is.rdstate();
  is.clear();
  std::string str;
  while (is >> str)
    std::cout << str << " ";
  std::cout << std::endl;
  is.clear();
  //is.setstate(old_state);
  return is;
}

int main() {
  std::string str;
  std::getline(std::cin, str);
  std::istringstream iss(str);
  read(iss);

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now