简体   繁体   中英

Not getting lines - std::getline

I posted this question a couple of days back and i just have another question, I have it outputting the first line of the data but it inst outputting the rest of the lines kinda stumped.

ifstream myReadFile;
    myReadFile.open("Data.txt");
    system("cls");
    std::cout << "Wip" << std::endl;

    ifstream myReadFile;
     myReadFile.open("Data.txt");
     std::string output;
     std::getline(myReadFile, output);
     std::cout << output << "\n";
     myReadFile.close();
system("pause");
return 0;

sample data

Name: jobes lobes
Age: 89
Address: 9 neuern_st mucgregor brosbane australia

You need to use a while loop so you can extract continuously. Extraction will finish when the stream fails to extract:

while (std::getline(myReadFile, output))
{
    std::cout << output << "\n";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM