c++ - Showing txt file details -
i have .txt file these contents: good bad hi i want next button cycle through these words, code word "good". when click next, doesn't show next word. here code qt 5.4 . void mainwindow::on_next_clicked() { ui->showen->clear(); ifstream sfile("e:\\en.txt"); getdata(sfile); sfile.close(); } void mainwindow::getdata(std::ifstream& myfile) { if(!myfile.eof()) { std::string str; getline(myfile, str); ui->showen->settext(qstring::fromstdstring(str)); } } every time method executed: void mainwindow::on_next_clicked() { ui->showen->clear(); ifstream sfile("e:\\en.txt"); getdata(sfile); sfile.close(); } the file opened anew , first bit read getdata. file closed. every time file opened, reading starts on beginning, why see same string every time. you want open file somewhere else (the window's constructor, perhaps?), read on each button c...