Has*_*eed 1 c++ templates vector
我创造了一款面向年轻观众的游戏,并试图过滤掉亵渎和冒犯的名字
#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;
}
Run Code Online (Sandbox Code Playgroud)
我在编写错误时谈到"模板参数",就行了std::vector,这是什么意思?
您需要为矢量提供模板参数.由于你持有字符串,你需要声明它:
std::vector< std::string > bannedSent = {
"Gosh",
"Golly",
"Jeepers",
"Troll"
};
Run Code Online (Sandbox Code Playgroud)