Sort a string array with sort() : sort « STL Algorithms Sorting « C++






Sort a string array with sort()

  
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
   string words[5] = { "ABCD", "BCDEF", "CERF","DERT", "EFRE"};
   string*   where;

   where = find(words, words + 5, "CD");
   
   cout << *++where << endl;                
   
   sort(words, words + 5);
   
   where = find(words, words + 5, "ER");
   cout << *++where << endl;              
}
  
    
  








Related examples in the same category

1.Using an in-place generic sort algorithm
2.Sort a vector and print out the sorted elements
3.Sort all element in an array
4.Sort part of the elements in an array
5.Sort a vector into ascending order of id members
6.Sort elements in deque
7.Sort elements reversely with custom function
8.Using the generic sort algorithm with a binary predicate: greater
9.Use custom function and sort to sort strings by length
10.Sorting user-defined class
11.Sort the entire container
12.Sort into descending order by using greater
13.Sort a subset of the container
14.Sort random number