Storing Strings in a Sequence, Use a vector for array-like storage of your strings. - C++ STL

C++ examples for STL:vector

Description

Storing Strings in a Sequence, Use a vector for array-like storage of your strings.

Demo Code

#include <string>
#include <vector>
#include <iostream>

using namespace std;

int main() {/*from   www.j  a v  a  2 s  .c  o  m*/

   vector<string> v;

   string s = "one";
   v.push_back(s);

   s = "two";
   v.push_back(s);

   s = "three";
   v.push_back(s);

   for (int i = 0; i < v.size(); ++i)
   {
      cout << v[i] << '\n';
   }
}

Result


Related Tutorials