I am using Qt5.2.1 I made a program that stores some values(like name, number, other details...) in a text file. I want to arrange this information according to the name.

Something like this.

A
Alan 24140239 some_other_info
Avril 64376334 some_other_info

B
bob 532523 some_other_info

And so on

Off the top of my head, create a vector<string> object, store every line as a string in the vector, add the strings A, B, C ... Z, use the standard algorithm sort function on the vector, and you've got a sorted vector<string> with A, B, C ... Z as you wanted. Write it out to text line by line.

And when you hit the next letter ...

i.e. when you reach B after printing all the A's ...
print a blank line

You may need to first switch to UPPER case every first letter in the names ... if some were entered with lower case first letters ... and then do the sort ... before you attempt the above.

If you can't easily access the info for each data record,

i.e if better to NOT write to file as one long string ...

you may need to use a struct and write each member on a separate line

and then read back, filling up a struct, and add each struct to a vector (or what ever STL container you prefer) as you go.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.