📄 cfile.cpp
字号:
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include "io.h"
#include <windows.h>
#include "file.h"
using namespace std;
void Filekeyword::GetKeyword(void)
{
string sKeywordFilename="keyword.txt";//"d:\\Summarize\\keyword.txt";
string sContaint;
string sub;
int pos1=0;
int pos2=0;
int filelength=0;
int nCount=0;
long hFile;
long hFile_all;
struct _finddata_t TrainFile;
if ((hFile= _findfirst(sKeywordFilename.c_str(),&TrainFile))==-1L)
{
cout<<"路径无法访问!"<<endl;
}
else
{
ifstream Fin(sKeywordFilename.c_str());
getline(Fin,sContaint,'\0');
Fin.close();
filelength=sContaint.size();
//cout<<filelength<<endl;
while ((pos2=sContaint.find("\n",pos1))!=-1&&pos2<=filelength)
{
sub=sContaint.substr(pos1,pos2-pos1);
//cout<<sub<<endl;
mKeywords.insert(tMap::value_type(sub,nCount));
//cout<<nCount<<endl;
nCount++;
pos2++;
pos1=pos2;
}
}
}
void Filekeyword::KeywordAnalysis()
{
long hFile;
int pos1=0;
int pos2=0;
int pos3=0;
int a=0;
int b=0;
int filelength=0;
int nweight;
string sFilepath="search\\*.txt";
string strFileName;
string strFileTemp;
string containt;
string sub;
string sweight;
struct _finddata_t TrainFile;
tMap::iterator it;
for(int i=0;i<20;i++)
for(int j=0;j<3;j++)
{
re[i][j]=0;
}
if ((hFile= _findfirst(sFilepath.c_str(),&TrainFile))==-1L)
{
cout<<"路径无法访问!"<<endl;
}
do {
strFileName=TrainFile.name;
// cout<<strFileName<<endl;
strFileTemp="search\\"+strFileName;
ifstream Fin(strFileTemp.c_str());
containt="";
getline(Fin,containt,'\0');
Fin.close();
filelength=containt.size();
//pos1=pos2=pos3=0;
// cout<<"第"<<a<<"篇"<<endl;
while ((pos2=containt.find("\t",pos1))!=-1&&(pos3=containt.find("\n",pos1))!=-1&&(pos3=containt.find("\n",pos1))<=filelength)
{
//pos3=containt.find("\n",pos1);
sub=containt.substr(pos1,pos2-pos1);
sweight=containt.substr(pos2+1,pos3-pos2-1);
// cout<<sub<<" "<<sweight<<endl;
nweight=atoi((char *)sweight.c_str());
it=mKeywords.find(sub);
if (it!=mKeywords.end()) {
b=(*it).second;
re[a][b]=nweight;
//cout<<re[a][b]<<endl;
}
pos3++;
pos1=pos3;
}
//cout<<a<<endl;
a++;
pos1=pos2=pos3=0;
} while(!_findnext(hFile,&TrainFile));
}
void Filekeyword::show()
{
for(int i=0;i<20;i++)
for(int j=0;j<3;j++)
{
cout<<re[i][j]<<" ";
if (j==2)
{
cout<<endl;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -