這是我修C++ Lab題目
Read all the words from Alice_stroy1.txt using istream_iterator and write all unique words in a size order into cout using ostream_iterator. For those of the same size, write them in an alphbetic order. 1 /**/ /* 2(C) OOMusou 2006 http://oomusou.cnblogs.com 3 4Filename : stream_iterator_alice.cpp 5Compiler : Visual C++ 8.0 / ISO C++ 6Description : Demo how to transform() & sort() & stable_sort() 7Release : 12/17/2006 1.0 8*/ 9 #include < fstream > 10 #include < iterator > 11 #include < vector > 12 #include < algorithm > 13 #include < iostream > 14 #include < string > 15 #include < cctype > // ispunct() 16 17 using namespace std; 18 19 bool sortRule( const string & , const string & ); 20 string noPunct( const string & ); 21 22 int main() { 23 ifstream inFile("Alice_story1.txt");2425 vector<string> svec;26 // Copy ifstream to vector27 copy(istream_iterator<string>(inFile), istream_iterator<string>(), back_inserter(svec));2829 // transform vector, cutting off punctuation30 transform(svec.begin(), svec.end(), svec.begin(), noPunct);31 // Sort vector for unique32 sort(svec.begin(), svec.end());33 // Unique vector34 vector<string>::iterator iter = unique(svec.begin(), svec.end());35 svec.erase(iter, svec.end());36 37 stable_sort(svec.begin(), svec.end(), sortRule);38 // Copy to cout39 copy(svec.begin(), svec.end(), ostream_iterator<string>(cout,"\n"));40 return 0;41} 42 43 <img id=Codehighlighter1_1166_1200_Closed_Image style="DISPLAY: none" οnclick="this.style.display='none'; Codehighlighter1_1166_1200_Closed_Text.style.display='none'; Codehighlighter1_1166_1200_Open_Image.style.display='inline'; Codeh