1
我正在寫程序我需要找到一個字符串數組中的特定單詞的位置,但我不知道如何。這是我做的代碼,但它不起作用:如何在C++中查找字符串數組中的單詞位置?
int location;
string input;
cout << "Type your name" << endl;
cin >> input;
for (int i = 0; i <= count; i++)
{
call_DB[i].name;
if (call_DB[i].name == input)
{
location = i;
}
}
該代碼有什麼問題,我該怎麼做才能解決它?謝謝。
std :: string :: find? – Steephen
可能的重複[如何從字符串查找子字符串?](http://stackoverflow.com/questions/13195353/how-to-find-substring-from-string) – CaptainTrunky
我不認爲我們有足夠的信息來回答這個問題。嘗試在調試器中檢查call_DB [...]的內容,查看空白。將字符串存儲在std :: set,std :: unordered_set或std :: map等快速((O)log(N)或甚至(O)1)而不是(O)的STL容器中也是值得的。 N)查找時間。 – JeremiahB