[求助]中英文标点识别,大家讨论下这个程序~
我在条件中设置了标点中断,但是在程序执行的时候不识别英文标点是怎么回事?就是遇到半角"?"就换行,但是遇到英文的" ?"时候却不能识别,大家能帮忙解决下么?
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
bool IsSplitMark(char ch[4])
{
char* Mark[]={",","。",";","!","?",":","?",",",".","!",":","……",";"};
for(int i=0;i<sizeof(Mark)/sizeof(char *);i++)
{
if(memcmp(ch,Mark[i],2)==0)
return true;
}
return false;
}
int main(int argc ,char *argv[])
{
cout<<"Input file Name:"<<endl;
string fileName;
getline(cin,fileName, '\n');
ifstream reader;
reader.open(fileName.c_str());
if(!reader.is_open())
{
cout<<"can't open Input file "<<fileName<<endl;
return -1;
}
vector<string> textList;
vector<char> chVec;
while(!reader.eof())
{
char chBuffer[2];
reader>>chBuffer[0];
if(!reader.good())
break;
if(chBuffer[0]<0)
{
reader>>chBuffer[1];
if(!reader.good())
break;
}
if(IsSplitMark(chBuffer))
{
chVec.push_back(chBuffer[0]);
chVec.push_back(chBuffer[1]);
string tmpStr(chVec.begin(),chVec.end());
textList.push_back(tmpStr);
//cout<<tmpStr<<endl; //结果显示
chVec.clear();
continue;
}
chVec.push_back(chBuffer[0]);
if(chBuffer[0]<0)
{
chVec.push_back(chBuffer[1]);
}
}
vector<int> Texts;
cout<<"结果"<<endl;
int iMaxLens=0;
int i;
for( i=0;i<textList.size();i++)
{
cout<<textList[i]<<endl;
Texts.push_back(textList[i].length());
if(Texts[i]>iMaxLens)
iMaxLens=Texts[i];
}
cout<<"分类结果:"<<endl;
for( i=1;i<iMaxLens/2+1;i++)
{
cout<<"第"<<i<<"类("<<i<<"个字符)"<<endl;
ofstream writer;
char nameBuffer[256];
sprintf(nameBuffer,"%d.txt",i);
writer.open(nameBuffer);
for(int j=0;j<Texts.size();j++)
{
if(Texts[j]==2*i||Texts[j]==2*i-1){
cout<<textList[j]<<endl;
writer<<textList[j]<<endl;
}
}
writer.close();
}
}
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
bool IsSplitMark(char ch[4])
{
char* Mark[]={",","。",";","!","?",":","?",",",".","!",":","……",";"};
for(int i=0;i<sizeof(Mark)/sizeof(char *);i++)
{
if(memcmp(ch,Mark[i],2)==0)
return true;
}
return false;
}
int main(int argc ,char *argv[])
{
cout<<"Input file Name:"<<endl;
string fileName;
getline(cin,fileName, '\n');
ifstream reader;
reader.open(fileName.c_str());
if(!reader.is_open())
{
cout<<"can't open Input file "<<fileName<<endl;
return -1;
}
vector<string> textList;
vector<char> chVec;
while(!reader.eof())
{
char chBuffer[2];
reader>>chBuffer[0];
if(!reader.good())
break;
if(chBuffer[0]<0)
{
reader>>chBuffer[1];
if(!reader.good())
break;
}
if(IsSplitMark(chBuffer))
{
chVec.push_back(chBuffer[0]);
chVec.push_back(chBuffer[1]);
string tmpStr(chVec.begin(),chVec.end());
textList.push_back(tmpStr);
//cout<<tmpStr<<endl; //结果显示
chVec.clear();
continue;
}
chVec.push_back(chBuffer[0]);
if(chBuffer[0]<0)
{
chVec.push_back(chBuffer[1]);
}
}
vector<int> Texts;
cout<<"结果"<<endl;
int iMaxLens=0;
int i;
for( i=0;i<textList.size();i++)
{
cout<<textList[i]<<endl;
Texts.push_back(textList[i].length());
if(Texts[i]>iMaxLens)
iMaxLens=Texts[i];
}
cout<<"分类结果:"<<endl;
for( i=1;i<iMaxLens/2+1;i++)
{
cout<<"第"<<i<<"类("<<i<<"个字符)"<<endl;
ofstream writer;
char nameBuffer[256];
sprintf(nameBuffer,"%d.txt",i);
writer.open(nameBuffer);
for(int j=0;j<Texts.size();j++)
{
if(Texts[j]==2*i||Texts[j]==2*i-1){
cout<<textList[j]<<endl;
writer<<textList[j]<<endl;
}
}
writer.close();
}
}