ifstream integers

Started by
0 comments, last by Motwner 22 years, 3 months ago
how can I read in more than one integers on a line using ifstream?
Advertisement
ifstream considers two integers on the same lime separate integers as long as there is whitesapce in-between them. So if the file looks like this:

18 32 36 14 95

You can just read it like this:

  std::ifstream file;file.open("myfile.txt");int num[5];file >> num[0] >> num[1] >> num[2] >> num[3] >> num[4];  


you could just as easily do:

  file >> num[0];file >> num[1];file >> num[2];file >> num[3];file >> num[4];  


No, HTML is not an OO language.

This topic is closed to new replies.

Advertisement