These are some basic functions that you will come across while learning C++.

c++

Sorting

Use the std::sort() function to sort arrays and vectors in ascending order. Sort will include the beginning pointer but not the ending pointer.

#include <algorithm>

sort(begin, end, wayToSort (optional))

For arrays

int size = 5;
int myArray[size] = {45, 2, 76, 62, 15};
sort(myArray, myArray+size);

or using C++ 11,

sort(begin(myArray), end(myArray));

For vectors

#include <vector>
#include <algorithm>

vector<int> myVector = {98, 26, 72, 12, 35, 65};
sort(myVector.begin(), myVector.end());

To sort in alphabetical order

#include <vector>
#include <string>
#include <algorithm>

vector<string> myVector = {98, 26, 72, 12, 35, 65};
sort(myVector.begin(), myVector.end());

Using a comparing function

Define your own function to use in sorting. To sort the above array in descending order:

bool wayToSort(int i, int j) { return i > j; }
sort(myVector.begin(), myVector.end(), wayToSort);

Substring of a string

substr(position, length)

If length is not given, the string up to the end is taken.

string myString = "This is a sentence";
myString.substr(5, 2);                   //"is"
myString.substr(10);                     //"sentence"

Happy coding in C++!