End of The File With atEnd
General and Desktop
3
Posts
3
Posters
755
Views
1
Watching
-
wrote on 29 Sept 2014, 19:27 last edited by
hi all
this is my prog@ QCoreApplication a(argc, argv);
QString path("e:\digi.txt");
QFileInfo info(path);int x; int *b; b=new int; QFile ready(path); ready.open(QIODevice::ReadOnly); QTextStream point(&ready); while(!ready.atEnd()){ point>>x; } ready.close(); int k; k=info.size(); qDebug()<<x;@
now this code wont print latest data in the text file but will print the first data in the text file why?
thanks -
If you want to read a binary file, use QDataStream. Since you seem to be opening a text file, however, you should open it with QFile::Text flag in addition to QFile::ReadOnly.
I suggest first reading the data into a QString to see what is being read, then translate it to an integer.
-
wrote on 1 Oct 2014, 04:29 last edited by
Hi..Use
ready.open(QIODevice::ReadOnly|QIODevice::Truncate);//at line 9
hope it helps
1/3