Parse it as if you were parsing any file and just keep track of when an empty line occurs:
#include <sstream> #include <fstream> #include <string> int main() { std::ifstream infile("thefile.txt", "rb"); std::string line; while (std::getline(infile, line)) // or std::cin instead of infile { if (line == "") { break; } // this is the exit condition: an empty line double d1, d2; std::string s1, s2; std::istringstream ss(line); if (!(ss >> d1 >> d2 >> s1 >> s2)) { /* error */ } // process d1, d2, s1, s2 } // move on }
source share