Defect man

xiaoxiao2021-04-01  222

/ ************************************************* **************************** * Ex13-2.cpp: Defines the entry point console application. * Run: * From a file, you read all the words in a file, then sort, and make a pair * question with the original words: * For the for_each algorithm, can the function pass multiple parameters? If you can, how to do * Error : * Because of the same item in MAP, it is lost here, so this will be lost here. **************************************************************************************************************************************************************************************************************************************************** ********************************************* * History: ** ************************************************** ************************** * 20 JUN 2006 XMC Create **************** ************************************************** ************ /

#include "stdafx.h" #include #include #include #include #include #include

Using namespace std;

Void PrintWord (String & Str) {cout << str << endl; return;}

void SortWord (string & str) {sort (str.begin (), str.end ()); return;}

INT main (int Argc, char * argv []) {// read the word from the file and put it in a vector, the member of Vector is Pair Map mapwords; Vector TmpWords; Vector < String> Oldwords; string filename ("c: //hello.txt"); ifstream IFS (filename.c_str ()); if (! ifs._open ()) {cout << "file open failed!" << Endl Return -1;} cout << "Successfully opened the file, is reading data from the file ....." << endl; copy (istream_iterator (ISTREAM_ITERATOR (), Back_INSERTER TmpWords)); Copy (TmpWords.Begin (), tmpwords.end (), Back_INSERTER (OldWords)); for_each (TmpWords.Begin (), TmpWords.end (), Printword;

Cout << "Sorting each word" << Endl; for_each (TmpWords.Begin (), TmpWords.end (), Sortword; for_each (tmpwords.begin (), tmpwords.end (), printword;

// After it, I have nothing to do, I have to make up the vector :: item ipgin; vector :: item ore1 = Oldwords.begin (); for (iter = tmpwords.begin (); ore! = Tmpwords .end (); iter ) {mapwords.insert (mapwords.end (), make_pair (* iter, * iter1)); iTer1 ;} // Print last operation result cout << "Print last operation results ... "<< Endl; Map :: itemimap = mapwords.begin (); for (; itute); oremap! = mapwords.end (); utermap ) {cout << Endl; cout << (* Itermap .first << endl; cout << (* oremap). SECOND << Endl;}

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-131181.html

New Post(0)