CPP Map

Maps in CPP are used to store sorted key-value pair. They are the associative containers. Each key in a map is unique. CPP facilitates insertion and deletion of a key in a map but do not allow any modifications, however, values can be modified. Member Functions of a CPP map: Allocator: FUNCTION USES get_allocator To … Read more

Categories CPP

CPP Queue

Queue is a data structure in CPP that works on FIFO (First In First Out) technique, which means that the first inserted element will be deleted first in a queue. Syntax: template<class T, class Container = deque<T> > class queue; Member Types of CPP Queue: MEMBER TYPE USES container_type To specify underlying container type. const_reference … Read more

Categories CPP

CPP Stacks

Stack is a data structure in CPP that works on LIFO (Last In First Out) technique, which means that the last inserted element will be deleted first in a stack.   Syntax: template<class T, class Container = deque<T> > class stack;   T: It is used to represent the type of the element that the … Read more

Categories CPP

CPP Set

Sets in CPP are used to store sorted key. They are the associative containers. Each key in a set is unique. CPP facilitates insertion and deletion of a key in a set but do not allow any modifications. Member Functions of a CPP Set: Allocator: FUNCTION USES get_allocator To return an allocator object to construct … Read more

Categories CPP

CPP List

The function of List is more or less same as CPP vector, however unlike the CPP vectors, CPP list is a contiguous container which supports a bidirectional insertion and deletion operations. In CPP list, elements are accessed sequentially Which results in slow traversal. Syntax 1: list <data_type>  list_name{value1, value2, …….}; Syntax 2: list <data_type>  list_name … Read more

Categories CPP

CPP Deque

Double ended queue or Deque in CPP is used for insertion and deletion of data from both the front end and the back end of a queue. Syntax: deque <object_type> deque_name; CPP Deque Functions FUNCTION USES at() To access the element at position pos. assign() To assign new content to the deque, replacing the old … Read more

Categories CPP

CPP Vector

A vector in CPP is used to implement a dynamic array. Vector in real, is a sequence container class. Here, dynamic array means that the array size automatically resizes itself when appending elements at run time. However, in static array, array size cannot be changed during run time. Syntax: vector <object_type> vector_name; CPP Vector Functions: … Read more

Categories CPP

CPP File & Stream

CPP standard library fstream is used to create a file, to read the data from a file and to write the data into a file in CPP programming. There are three data types defined in fstream library. These are: fstream: Used to create a file, to read the data from a file and to write … Read more

Categories CPP

CPP User-Defined Exceptions

CPP facilitates the feature of defining any new error by a user in a CPP program, by overriding and inheriting exception class functionality. Example: #include <iostream> #include <exception> using namespace std; class newException : public exception { public: const char * what() const throw() { return "Divide by zero error!"; } };   int main … Read more

Categories CPP

CPP Try Catch

Exception handling is necessary in an efficient code, as if it is not handled properly, further execution of code stops as soon as any exception occurs. Try, Catch and Throw are the keywords used for exception handling in CPP. Steps for Exception Handling in CPP: The suspicious code which can raise an exception is enclosed … Read more

Categories CPP