//: C04:StringVector.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // A vector of strings #include "../require.h" #include #include #include #include #include #include using namespace std; int main(int argc, char* argv[]) { requireArgs(argc, 1); ifstream in(argv[1]); assure(in, argv[1]); vector strings; string line; while(getline(in, line)) strings.push_back(line); // Do something to the strings... int i = 1; vector::iterator w; for(w = strings.begin(); w != strings.end(); w++) { ostringstream ss; ss << i++; *w = ss.str() + ": " + *w; } // Now send them out: copy(strings.begin(), strings.end(), ostream_iterator(cout, "\n")); // Since they aren't pointers, string // objects clean themselves up! } ///:~