0

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

3
Contributors
2
Replies
15
Views
3 Years
Discussion Span
Last Post by David W
0

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.

0

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.

Edited by David W: fixed text

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.