C++ vector store string objects

Description

C++ vector store string objects

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()/* ww w .ja v  a2  s . c  o  m*/
{
   vector<string> vectStrings;
   string word;
   char ch;
   do {
      cout << "Enter a word: ";
      cin >> word;
      vectStrings.push_back(word);
      cout << "Enter another ('y' or 'n'): ";
      cin >> ch;
   } while(ch == 'y');
   sort( vectStrings.begin(), vectStrings.end() );
   for(int k=0; k<vectStrings.size(); k++)
      cout << vectStrings[k] << endl;
   return 0;
}



PreviousNext

Related