Skip to content

July 18, 2014

Create a Vector of Strings and Iterate Through it in C++

by noise

In the next example we will create a vector of strings and will iterate through it (main.cpp).

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    string str1[] = {"the", "brown", "fox", "jumped", "over", "the", "lazy", "dog"};
    vector<string> vector1(str1, end(str1));
    for (int i; i < vector1.size(); i++) {
        cout << vector1[i] << endl;
    return 0;
Read more from C and C++ Examples

Leave a Reply


Note: HTML is allowed. Your email address will never be published.

Subscribe to comments