Today we practice file I/O while introducing more useful functions in the C++ STL.
Sorting
Apart from vectors and arrays, we can also use sort on strings.
To sort a vector of int in descending order,
use sort(v.begin(), v.end(), greater<int>()).
<algorithm>
swap(a, b)swaps the contents ofaandbcount(s.begin(), s.end(), 'x')counts the number of occurrences of the character'x'in the stringsreverse(s.begin(), s.end())reverses a sequence
<string>
Functions that check if a character is part of a category (returns a boolean):
isalpha(c)- ifcis a - z or A - Zislower(c)- ifcis a - zisupper(c)- ifcis A - Zisdigit(c)- ifcis 0 - 9isalnum(c)- ifcis a - z, A - Z or 0 - 9isspace(c)- ifcis a space character (e.g. space, new line, tab)
Type conversion:
to_string(n)- converts integernto stringstoi(s)- converts stringstointstoll(s)- converts stringstolong long
Authored by s16f22