- ----------以前的代码删除了 因为太恶心了 又重写了一份------------
- #include <iostream>
- #include <map>
- #include <fstream>
- #include <cctype>
- using namespace std;
- map<string,int> wordmap;
- void procline(char *line)
- {
- char word[64]={0};
- for( int i=0; line[i]!='\\0'; i++ )
- {
- int n=0;
- while( isalpha(line[i]) ) //Ñ-»・μ½ÏÂò»¸ö・Ç×Öĸ×Ö・û
- {
- word[n++]=tolower( line[i++] );// μ¥′ê×a»ˉÎaD¡D′
- }
- word[n]='\\0';
- if( strlen(word) > 4 )//1yÂË1y¶ìμÄμ¥′ê
- {
- ++wordmap[word];
- }
- }//for
- }
- int main()
- {
- map<string,int>::iterator iter;
- fstream infile,outfile;
- infile.open("K:\\\\1.txt",std::ios::in);
- if( !infile)
- {
- cout << "open the file error!" << endl;
- return 1;
- }
- char buf[2048];
- while( !infile.eof() )
- {
- infile.getline(buf,2048);
- procline(buf);
- }
- infile.close();
- outfile.open("K:\\\\2.txt",ios_base::out);
- iter = wordmap.begin();
- while( iter != wordmap.end() )
- {
- if( iter->second > 20 )//出现次数大于多少次则记录
- outfile << iter->first << "\\t" << iter->second << "\\x0d\\x0a";
- iter++;
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/100420149294.html
来源: http://www.codesnippet.cn/detail/100420149294.html