Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to call the function that accepts std::istream&

I am a beginner in c++ so thank you in advance for help. My question is: what is the correct way to call the function that expects std::istream&.
Tried it with read(std::cin); , but I get error from compiler.

typedef double Element;

template<typename T>
std::list<T> read(std::istream& i) {  
  Element input;
  std::list<Element> l;
  while(i>>input) {
   l.push_back(input);
  }
  return l;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is not related to the std::istream& parameter.

The issue is that the function is a function template that requires an explicit template argument determining the type that is supposed to be read from the stream, e.g.:

read<int>(std::cin)

The error message from the compiler should be telling you something like that as well.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading