How can i sort (ascending or descending) an array of CString‘s? I saw a lot of references to std::vector, but i can’t find an example of converting a CString array to a vector.
How can i sort (ascending or descending) an array of CString ‘s? I saw
Share
Assuming that
CStringmeans ATL/MFCCString, complete demo program usingstd::sortto sort a raw array:Using a
std::vectorinstead of a raw array is a little bit more intricate, since Visual C++’s standard library implementation does not yet supportstd::initialiser_listper version 11.0. In the example below I use a raw array to provide the data (this is an example of converting aCStringarray to astd::vector, as you ask for). But the data could conceivably come from any source, e.g. reading the strings from a file:As you can see, there is no difference in how the
std::vectoris used, compared to the raw array. At least at this level of abstraction. It’s just more safe and with more rich functionality, compared to the raw array.