ifstream file("test.txt");
while (file) {
getline(file, Name);
getline(file, Species);
getline(file, Location);
file >> Length;
file >> Weight;
if (file) {
cout << Name << "
" << Species << "
" <<Location << "
" <<Length << "
";
// add this to skip the 2 newlines before reading the next string
file.ignore(std::numeric_limits<std::streamsize>::max(), '
');
file.ignore(std::numeric_limits<std::streamsize>::max(), '
');
}
else {
throw "Invalid input";
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…