//: C04:WordList2.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Eliminating strtok() from Wordlist.cpp #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]); istreambuf_iterator p(in), end; set wordlist; while (p != end) { string word; insert_iterator ii(word, word.begin()); // Find the first alpha character: while(!isalpha(*p) && p != end) p++; // Copy until the first non-alpha character: while (isalpha(*p) && p != end) *ii++ = *p++; if (word.size() != 0) wordlist.insert(word); } // Output results: copy(wordlist.begin(), wordlist.end(), ostream_iterator(cout, "\n")); } ///:~