In this article we will see a code example to work with vector of string in c++. To declare a vector of string, use vector<string> variable_name
. Then you can push string values to it.
Code Example –
#include <string> #include <vector> #include <iostream> using namespace std; int main() { vector<string> names_vector; names_vector.push_back("Ironman"); names_vector.push_back("Captain America"); names_vector.push_back("Hulk"); for (int i = 0; i < names_vector.size(); ++i) { cout << names_vector[i] << '\n'; } return 0; }