Category: std::vector
vector::at() function in C++
In C++ the vector class provides a function at() to return the value at the given index position. Let us see the syntax of the function, Table Of Contents Syntax of vector::at() function Example of vector::at() vector::at() and out_of_range exception Update vector using vector::at() Summary Syntax of vector::at() function reference at (size_type n); const_reference at …
How to cout a vector in C++
In this article, we will discuss how to print a vector using std::cout in C++. By default we can directly pass a vector object to the cout in C++. As, ‘cout’ calls the operator<<() function of each passed object. So, we can overload a operator<< function of vector like this, #include <iostream> #include <vector> /* …
Convert a String to a Vector of Bytes in C++
The article here discusses various ways to convert an input string to a vector of bytes in C++. Table Of Contents Method 1: Using a For Loop Method 2: Using std::vector Constructor Method 3: Using std::transform method Method 4: Using std::copy() method Summary Method 1: Using a For Loop This program creates a string called …
vector::erase() function in C++
In this article, we will discuss all about vector’s erase() function, and how to use the vector::erase() function in C++. Table Of Contents Remove single element from vector using erase() Removing multiple elements from vector using erase() function Using vector::erase() function in the for loop Summary In C++, the vector class provides a function erase() …
vector::insert() function in C++
In C++, the vector class provides a function insert(), to insert single or multiple elements before the element at the specified position. It increases, the size of vector by n. Where n is the number of elements inserted. Table Of Contents Introduction Using insert() function to insert single element in vector Using insert() function to …
Remove certain characters from a String in C++
In this article, we will learn how to remove certain characters from a string in C++. Table Of Contents Problem Description Method 1: Using while loop Method 2: Using STL function for_each(), erase() and remove() Special Notes about remove() and erase() Summary Problem Description Suppose we have a string sampleStr, and an array of characters …
C++ Vector – STL Tutorial
In this article, we will discuss what is a std::vector<> and how to use it in C++. Table Of Contents What is a vector in C++? How vector stores the data internally? How to create a vector in C++? Initialize a vector with n copies of same element Create an empty vector object and append …