sorting vector<string> in alphabetical order

hello all,

I know there is a function in algorithm class called sort()
but I need to sort ignoring the case of the alphabet

Is there any function that does that ?

thank you
1
2
template <class RandomAccessIterator, class Compare>
void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);

Just provide the appropriate comparison function
1
2
3
4
5
6
7
std::sort(std::begin(myvector), std::end(myvector), [](std::string const &a, std::string const &b)
{
    return std::lexicographical_compare(std::begin(a), std::end(a), std::begin(b), std::end(b), [](std::string::value_type a, std::string::value_type b)
    {
        return std::tolower(a) < std::tolower(b); //case-insensitive
    });
});
http://ideone.com/N6sq6X
Last edited on
Topic archived. No new replies allowed.