我正在阅读多个文档,并为我阅读的单词编制索引。但是,我想忽略常见的大小写单词(a、an、the、and、is、or、are 等)。
这样做有捷径吗?不仅仅是做...
if(word=="and"|| word=="is"|| etc etc....) 忽略单词;
例如,我能否以某种方式将它们放入 const 字符串中,并让它只检查字符串?不确定...谢谢!
最佳答案
创建一个 set<string>
用你想排除的词,然后使用 mySet.count(word)
以确定单词是否在集合中。如果是,计数将为 1
;它将是0
否则。
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
const char *words[] = {"a", "an", "the"};
set<string> wordSet(words, words+3);
cerr << wordSet.count("the") << endl;
cerr << wordSet.count("quick") << endl;
return 0;
}
关于c++ - 忽略几个不同的词.. c++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10158633/