我创建了一款适合年轻观众的游戏,并试图过滤掉亵渎和冒犯性的名字
#include <iostream>
#include <vector>
bool isBanned( std::string text ) {
std::vector bannedSent = {
"Profanity1",
"Profanity2",
"Profanity3",
"Profanity4"
};
for(auto &i : bannedSent) {
if(text == i) { return true; }
}
return false;
}
我在 std::vector
行中遇到有关“模板参数”的编译器错误,这是什么意思?
最佳答案
您需要为 vector 提供模板参数。由于您持有字符串,因此需要这样声明:
std::vector< std::string > bannedSent = {
"Gosh",
"Golly",
"Jeepers",
"Troll"
};
关于c++ - 将攻击性句子列入黑名单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35856659/