![]() |
In C++, std::vector are the dynamic array containers that replace the plain old C-style arrays and it is very common to assign the values of those C-Style to std::vector. In this article, we will learn how to assign a std::vector using C-style arrays. For Example, Input: Assign a C-Style Array to std::vectorTo assign a C-Style Array to std::vector, we can use the std::vector::assign() function that replaces the old values of the vector and assigns them the new values. We need to pass the starting and ending address of the array to the function as the argument. C++ Program to Assign Vector using C-Style ArrayC++
Output
Vector elements: 1 2 3 4 5 If we want to insert elements after the currently present elements in the vector, we can use the std::vector::insert() function. |
Reffered: https://www.geeksforgeeks.org
C++ Programs |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |