C++ fstream classes
The <fstream>
library provides classes for reading and writing into files or data streams.
A list of useful fstream classes can be found in the table below. Continue reading C++ fstream Library
The <fstream>
library provides classes for reading and writing into files or data streams.
A list of useful fstream classes can be found in the table below. Continue reading C++ fstream Library
The <iostream>
library provides objects which can read user input and output data to the console or to a file.
A list of all iostream objects can be found in the table below. Continue reading C++ iostream Library
A list of useful keywords in C++ can be found in the table below. Continue reading C++ Keywords
Iterators are used to access and iterate through elements of data structures (vectors, sets, etc.), by “pointing” to them.
It is called an “iterator” because “iterating” is the technical term for looping.
To iterate through a vector, look at the following example:
// Create a vector called cars that will store strings vector<string> cars = {"Volvo", "BMW", "Ford", "Mazda"}; // Create a vector iterator called it vector<string>::iterator it; // Loop through the vector with the iterator for (it = cars.begin(); it != cars.end(); ++it) { cout << *it << "\n"; }
A map stores elements in “key/value” pairs.
Elements in a map are:
To use a map, you have to include the <map>
header file:
// Include the map library
#include <map>
A set stores unique elements where they:
To use a set, you have to include the <set>
header file:
// Include the set library #include <set>
In the previous page, your learned that elements in a queue are added at the end and removed from the front.
A deque (stands for double-ended queue) however, is more flexible, as elements can be added and removed from both ends (at the front and the back). You can also access elements by index numbers.
To use a deque, you have to include the <deque>
header file:
// Include the deque library #include <deque>
A stack stores multiple elements in a specific order, called LIFO.
LIFO stands for Last in, First Out. To vizualise LIFO, think of a pile of pancakes, where pancakes are both added and removed from the top. So when removing a pancake, it will always be the last one you added. This way of organizing elements is called LIFO in computer science and programming.
Unlike vectors, elements in the stack are not accessed by index numbers. Since elements are added and removed from the top, you can only access the element at the top of the stack. Continue reading C++ Stacks
A list is similar to a vector in that it can store multiple elements of the same type and dynamically grow in size.
However, two major differences between lists and vectors are: