Q:

Write a function that takes and returns an istream&. The function should read the stream until it hits end-of-file. The function should print what it reads to the standard output. Reset the stream so that it is valid before returning the stream

0

Write a function that takes and returns an istream&. The function should read the stream until it hits end-of-file. The function should print what it reads to the standard output. Reset the stream so that it is valid before returning the stream.

All Answers

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

#include <iostream>
#include <string>

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() {
  read(std::cin);

  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