How do I define a function that reads a sequence of values from an input stream that is passed as an argument?

would something like this work?

void readHW(istream &arg  ) {

  double x ;
  do {
    arg >> x ;
  } while (x != -1 );


Using -1 as a flag , and then in the function I would pass cin as the argument? I know im not doing anything with the input but i just want to know how it works

You can simply open the ifstream in the function without passing anything. Why do you use that loop, is there a -1 in the file your reading from? If you want to read the whole file a better way would be:

while ( arg >> x )

The while loop would continue until it reaches the end of the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.