In this tutorial you will first learn about sorting, i.e. how to sort vectors and arrays. After that, you will also learn how to read from a file and write to a file using C++.
The easiest way to sort any container is with the sort() function from the algorithm library, which takes two arguments. First argument is the beginning address (container.begin()) of the container and second argument is the ending address (container.end()). Remember, this function doesn't return any value. Calling the sort function modifies the original container and the elements are arranged in sorted order.
The general syntax for sorting is:
sort(start address, end address)
start address = the address of the first element of the array / vector
end address = the address of the last element of the array / vector
Every variable you define is stored in memory and thus, has a location or address. Just like you live in your home and your home has an address, similarly variables also need a home, which is memory location in this case and their home also has an address.
That address can be accessed using the ampersand operator (&) (also called the address-of operator), which denotes an address in memory. For example:
We already learnt about strings in C++ Data-types, Operators and Strings, but in this tutorial we are going to learn a little more about C++ strings and also see some helpful functions C++ provides for strings.
String literals are enclosed in either double quotes.
For example, "Hello World" is a string.
To type in some special characters, you have to type in a backslash escape. For example, \" is a double quote, \\ is a backslash, \t is a tab and \n is a newline. For example, the following code: