![]() |
In C++, a vector is a dynamic array that can grow and shrink in size. A char array is a sequence of characters, typically used to represent strings. In this article, we will learn how to access elements in a vector of char arrays in C++. Example: Input: myVector = {“apple”, “banana”, “cherry”} Output: myVector[1] = banana Access Vector of Char Arrays Elements in C++We store the array of characters inside the vector as pointers. To access elements in a std::vector of char arrays in C++, we can use the operator[] that takes the index as an argument and returns the element at that index in the vector. C++ Program to Access Elements in a Vector of Char ArraysC++
Output
Accessing the elements in the vector using operator[] myVector[2]: cherry Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |