C++ examples for STL:vector
Vector to string objects, push_back(), and []
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main()/*from w w w.j a v a 2s.c om*/ { 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; }