Think of a vector as a more advanced array. I hope you are more familiar with those.
Vectors are less efficient, but safer (they expand or contract as needed, so you can't overrun the bounds) and can save some coding time (because they have convenient member functions that save you having to code lots of loops). Some of the member functions used here are:
.push_back( ) - adds another element to the end of the vector (making it one bigger)
.size() - returns the current length of the vector; unlike a normal array this can change as you add or delete elements
.erase() - remove an element and close up the remainder
Just as you can use a pointer to traverse the elements of an array, you can use an "iterator" to do roughly the same in a vector (fMarks.begin() returns an iterator (like a pointer) to the start of an array; adding i1 points i1 elements onward - just like pointers).
From the top, your program
- creates vectors to hold floating point numbers and integers respectively
- GetInfo reads marks from a file and, one-by-one, adds them (using push_back) to a vector
- the while loop in main goes through the marks and sends them to GetOccur, which does two things:
- counts the number of occurrences of a particular mark;
- removes this particular mark from the remainder of the array (note the .erase) so it isn't counted again.
- PrintVectors outputs the particular mark (from vector fmarks) and number of occurrences (from vector iCount)