我正在阅读几个文档,并将我读入的单词编入索引.但是,我想忽略常见的单词(a,an,the,and,is,or,等等).
这样做有捷径吗?莫索比做...
if(word =="和"|| word =="是"|| 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;
}
Run Code Online (Sandbox Code Playgroud)