Question about reading in data until none exists

Hi, I am looking for help creating a loop/while statement that loops until there is no data left in the input file. I ran into issues this time because the assignment requires us to perform all operations on the data in functions outside of the main() function. Basically, in a condensed form, I need to loop the following sub functions:

main()
{

readDataRow(); // I need to get these three functions to loop as long as...
validateData(); // data exists
printData();

}
This code calls three functions; one to read, one to validate, and one to print:
1
2
3
4
double value;
while ( std::cin >> value && value < 42.0 ) {
  std::cout << value << '\n';
}


Your functions have different names, but they too must take parameters and return something?
How i would approach this problem is:

solving: readDataRow + validate + print on screen:

1
2
3
4
5
6
7
8
string line;
ifstream data;
data.open("data.txt");
while(!data.eof()){
  data >> line;
  cout << line << " " ;
}


for ifstream u will need #include <fstream>
for string u will need #include <string>

Hope this will help...

Regards, Kristijan
Last edited on
Topic archived. No new replies allowed.