sorting string in cpp code example

Example 1: how to sort a string in c++

#include<bits/stdc++.h>
using namespace std;
int main()
{
	srting str; // First, declare a string.
  	sort(str.begin() , str.end()); // Then sort it by using this method. It is much more convenient.
  	cout << str << endl; // Last of all, print out the string.
}

Example 2: stl sort in c++

sort(arr, arr+n); // sorts in ascending order

Example 3: stl sort in c++

sort(arr, arr+n, greater<int>()); // sorts in descending order

Tags:

Cpp Example