我有一个名为aisha的txt文件,其中包含以下内容
This is a new file I did it for mediu.
Its about Removing stopwords fRom the file
and apply casefolding to it
I Tried doing that many Times
and finally now I could do我写了两个代码,一个是去掉一些停用的单词
#include <iostream>
#include <string>
#include <fstream>
int main()
{
using namespace std;
ifstream file("aisha.txt");
if(file.is_open())
{
string myArray[200];
for(int i = 0; i < 200; ++i)
{
file >> myArray[i];
if (myArray[i] !="is" && myArray[i]!="the" && myArray[i]!="that"&& myArray[i]!="it"&& myArray[i]!="to"){
cout<< myArray[i]<<" ";
}
}
}
system("PAUSE");
return 0;
}另一个是用于四个水壶的应用案例折叠
#include <iostream>
#include <string>
#include <fstream>
int main()
{
using namespace std;
ifstream file("aisha.txt");
if(file.is_open())
{
file >> std::noskipws;
char myArray[200];
for(int i = 0; i < 200; ++i)
{
file >> myArray[i];
if (myArray[i]=='I')
cout<<"i";
if (myArray[i]=='A')
cout<<"a";
if (myArray[i]=='T')
cout<<"t";
if (myArray[i]=='R')
cout<<"r";
else
if (myArray[i]!='I' && myArray[i]!='T' && myArray[i]!='R')
cout<<myArray[i];
}
file.close();
}
system("PAUSE");
return 0;
}现在我需要将这两个代码合并到一个代码中,删除停用词,然后应用案例折叠,问题是我使用了string myArray[200];作为停用词代码,char myArray[200];用于案例折叠代码,并且我不能只使用字符串或字符,我该怎么办?
发布于 2013-12-01 04:28:58
将文本处理器放在单独的函数中,并在main中逐个调用它们。将不会有名称和类型冲突。
下面是一个粗略的例子
void removeStopWords(ifstream file) {
// put your code here for removing the stopwords
}
void applyCaseFolding(ifstream file) {
// put your code here for applying case folding
}
int main() {
ifstream file("aisha.txt");
if(file.is_open()) {
removeStopWords(file);
applyCaseFolding(file);
}
return 0;
}https://stackoverflow.com/questions/20305106
复制相似问题