Titel ist nicht sehr informativ, aber im Grunde, was ich versuche zu tun, ist eine Prüfung gegen eine TXT-Datei und finde Wörter, die das, was ich suche.C++ sonst, wenn char in string
Der folgende Code tut es richtig und genau, wie ich es tun will. ABER!
void qu()
{
for (Word word : word2)
{
string uq = word.getWord();
if (uq.find("qa") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qb")!= std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qc") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qd") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qe") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qf") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qg") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qh") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qi") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qj") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qk") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("ql") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qm") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qn") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qo") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qp") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qq") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qr") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qs") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qt") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qv") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qw") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qx") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qy") != std::string::npos)
{
cout << uq << '\n';
}
else if (uq.find("qz") != std::string::npos)
{
cout << uq << '\n';
}
}
}
Ich möchte es auf eine sauberere Art und Weise tun.
Wenn mir jemand in die richtige Richtung zeigen könnte wie ein cplusplus Verweis Verweis oder eine andere Dokumentation, die toll wäre.
Wenn eine Antwort Ihre Frage wirklich beantwortet hat, dann bitte markieren Sie es als beantwortet. Kopiere die Antwort nicht in deine Frage! So funktioniert Stack Overflow nicht ... –
Wenn der Code funktioniert, ist es eher ein Fall von [Code Review] (https://codereview.stackexchange.com/), der eine eigene Site hat. –