1.

Vectors

Answer»
#include <vector>
int main() {
vector<int> grade(3);
grade[0] = 90;
grade[1] = 80;
grade[2] = 70;
return 0;
}

A vector in C++ is a dynamic list of things that can expand and shrink in size. It can only hold values of the same type. It is important to #include the vector library in order to use vectors.

vector<string> wishlist;
wishlist.push_back("Furniture");
wishlist.push_back("Basket");
wishlist.pop_back();
cout << wishlist.size(); // returns the output 1

  • push_back() function adds the value at the end of the vector.

  • pop_back() function removes the element from the end of the vector.

  • size() returns the size of the vector.




Discussion

No Comment Found