Hi guys. I am a bit confused among the following three functions.

read()
readAll()
readLine()

How do they work? I'll be really thankful to you all.

Thanks alot for your precious time!

Regards.

None of those are standard C++ functions. What library are you using to get them, or what compiler are you using if they're extended library functions?

I concluded that, readAll() reads every thing in the file. same goes for read(). But what is meant by "Reads at most maxlen characters from the stream".

for example i have saved the comments of some people in a file directly from the program i made. Each user before commenting is bound to type a special character at the start of comment. Now i want to load all the comments one by one in a Qlabel from that file. How can i recognise that the special character in the file has reached so that i can print the next Comment on another Qlabel.

If you give it a maxlen value, that's all it will read.
If you set the parameter to 10, it will read 10 characters from the stream.

Since it sounds like the amount of data the user can type is of variable length and that you recognize the next comment by a special character, I suggest you readAll() and then parse the QString (if it's not too much data).

If the amount you're trying to read is too much, you would need to read() the data based on the amount you can process at any time and parse that data based on the location of the special character. Any incomplete comment records would need to be joined totether.

Is that what you meant?

But what is meant by "Reads at most maxlen characters from the stream".

If you give it a maxlen value, that's all it will read.
If you set the parameter to 10, it will read 10 characters from the stream.

It will read up to 10 characters, but never any more. If there are fewer than 10 characters in the stream then they'll all be read. That's what 'at most' means in this context.

why does the IDE gives me error.

for(QStringList::Iterator it=list.begin();it!=list.end();it++)
    {
        QString current= it; // here is the error
        qDebug()<< current;
    }

Edited 3 Years Ago by Dani: Formatting fixed

so it means any kind of list i use, its iterator will return the pointer of the nodes of the list..

so it means any kind of list i use, its iterator will return the pointer of the nodes of the list..

Not really. It means that iterators in C++, at least the ones following convention, are an abstraction of pointers. They overload operators in such a way that they have a subset of pointer operations depending on the type of iterator. All iterators have a dereference operator to access the "pointed to" object.

Edited 4 Years Ago by deceptikon: n/a

This article has been dead for over six months. Start a new discussion instead.