// compile with: g++ hello.cpp #include<iostream> #include<string> #include<vector> using namespace std; int main(int argc, char * argv[]) { string s; // declares a vector of strings. vector is like an array. // note that for vector you don't have to declare size, it will allocate when needed. // note that vector is a templated type, you give it what kind of thing you want // to store, in this case string vector<string> words; // while there is input while (cin >> s) { // add the string to the words vector words.push_back(s); } // note: .size method in vector for(int i= words.size()-1; i >= 0; i--) cout << words[i] << endl; // loop through vector using iterator. a c++ iterator is generic // enough to work for vectors (array), lists (linked list), maps (bst) for (vector<string>::iterator it = words.begin() ; it != words.end(); ++it) cout << *it << endl; return 0; }