对于我的情况,我必须检查2个字符串是否相同。在万阿英,蒋达清我得到是,不管我投入,我得到一个真正的价值,无论是我插嘴说。检查字符串是否相同C++
bool Dictionary::checkIfWordExists(string input){
for(int counter=0;counter<234;counter++){
if(input.compare(getWordFromDictionary(counter))){
return true;
}
}
return false;}
出于测试目的,我用这样的做回路输入的东西与我加载的dictionary.txt文件进行比较来测试。
do{
cout<<"enter something you sexy beast"<<endl;
string test;
cin>>test;
if(loadedDictionary.checkIfWordExists(test)){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}while(true);
谢谢你......当我的问题很简单时,我觉得自己很迟钝。 Ahaha –
我认为值得注意的是,使用'=='运算符会比compare()函数更清晰和更正确。 –