// File: main2.C // // Sample program using STL vector templates // Read the "spell" dictionary and create a sequence // of random words #include #include #include #include #include #include // STL string template, like BString #include // STL algorithms main() { vector V ; ifstream ifile("words") ; // "words" is filename of dictionary string str ; // Get all strings from ifile // while (1) { ifile >> str ; if (ifile.eof()) break ; V.push_back(str) ; } random_shuffle(V.begin(), V.end()) ; cout << "10 random words" << endl ; for (int i = 0 ; i < 10 ; i++) { cout << V.back() << endl ; V.pop_back() ; // remove last element } }