# if! Defined (AFX_WORDPROCESS_H__DC6CE2F6_54C5_47DE_A1FF_F5C87B8C309F__INCLUDED_)
# define AFX_WORDPROCESS_H__DC6CE2F6_54C5_47DE_A1FF_F5C87B8C309F__INCLUDED_
# if _MSC_VER & gt; 1000
# pragma once
# endif//_MSC_VER & gt; 1000
# include & lt; string>
# include & lt; Vector>
# include & lt; Algorithm>
using namespace std;
Typedef struct WORD_FREQ
{
String strword;
Int freq.
} WF.
The class CWordProcess
{
Public:
Void the OutPut ();
Void PushVector (string word);
Void the Split (char * PSTR, char * pword);
Void the ProcessFile ();
CWordProcess (string filesrc, string filedest);
Virtual ~ CWordProcess ();
Private:
VectorM_vector;
String FileDestPath;
String FileSrcPath;
The FILE * fr;
The FILE * fw;
};
# endif//! Defined (AFX_WORDPROCESS_H__DC6CE2F6_54C5_47DE_A1FF_F5C87B8C309F__INCLUDED_)
# include "stdafx. H"
# include & lt; stdio.h>
# include "WordProcess. H"
//////////////////////////////////////////////////////////////////////
//Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWordProcess: : CWordProcess (string filesrc, string filedest)
{
FileSrcPath=filesrc;
FileDestPath=filedest;
}
CWordProcess: : ~ CWordProcess ()
{
The fclose (fw);
The fclose (fr);
}
Void CWordProcess: : ProcessFile ()
{
Fr=fopen (FileSrcPath c_str (), "r");
Fw=fopen (FileDestPath c_str (), "w");
Char szBuf [200]={} '\ 0';
Char szWord [200]={} '\ 0';
while(! The feof (fr))
{
Fscanf (fr, "% s", szBuf);
The Split (szBuf, szWord);
Printf (" % s ", szWord);
PushVector (szWord);
}
The OutPut ();
}
Void CWordProcess: : Split (char * PSTR, char * pword)
{
Char * p=PSTR;
Char * p=STRCHR (p, '/');
If (p1!=NULL)
{
* p1='\ 0';
Strcpy (pword, p);
}
}
Void CWordProcess: : PushVector (string word)
{
WF WF.
Vector: : iterator iter.
For (iter=m_vector. The begin (); iter!=m_vector. End (); Iter++)
{
Wf=(wf) * iter;
If (wf) strword==word)
{
Wf. Freq++;
* iter=wf;
return;
}
}
Wf. Strword=word;
Wf. Freq=1;
M_vector. Push_back (wf);
}
Void CWordProcess: : the OutPut ()
{
WF WF.
Vector: : iterator iter.
For (iter=m_vector. The begin (); iter!=m_vector. End (); Iter++)
{
Wf=* iter.
Fprintf (fw, "% s", wf. Strword. C_str ());
Fprintf (fw, "% d", wf, freq);
Fprintf (fw, "\ n");
}
}
# include "stdafx. H"
# include "WordProcess. H"
Int main (int arg c, char * argv [])
{
String strfilesrc="d: \ \ 199801. TXT";
String strfiledest="d: \ \ result. TXT";
CWordProcess f (strfilesrc strfiledest);
F.P rocessFile ();
Printf (" Hello World! \n");
return 0;
}
This is by reading the file
http://pan.baidu.com/s/1sj1Gl7Rhttp://pan.baidu.com/s/1sj1Gl7R
CodePudding user response:
for helpCodePudding user response:
Remember the vector sorting professional# include & lt; Algorithm>
Sort (v_ResList. The begin (); V_ResList. End ());
CodePudding user response: