I am attempting to sort a vector of string elements in alphabetical order, outputting them using an iterator. The Vector elements are in the following format:
PHYS 30485 Physics of lasers
(This is an example element, but every element follows this format) You have "PHYS" followed by a whitespace then 5 digits, followed by a second whitespace before a string. Each of these elements are entered in on one line. Nothing fancy here.)
The issue here is when I write my sort line it automatically sorts by integer order (using the 5 digit number), whereas I want it to sort using the string
after the 5 digits.
The code I'm using to sort each element in the array is as follows:
1 2 3 4 5
|
vector<string>::iterator namestart{ matchingcourses[0] }, nameend{ matchingcourses.end() };
vector<string>::iterator j2;
sort(namestart., nameend);
for (j2 = namestart; j2 < nameend; j2++, compareFunction)
cout << *j2 << endl;
|
(The "matchingcourses" is a vector that contains multiple of the elements in the example format previously stated)
So my question summarised is simply: How do I make this code sort alphabetically by name, rather than defaulting to the ascending order of the integers, whilst still outputting the full element in the specified format?