c++ meine strings vergleichen nicht den eingegebenen Username

threem

Newbie
Registriert
Mai 2020
Beiträge
3
#include <iostream>
#include <string>
using namespace std;

int main()
{
string UserIDAttempt;
string PasswordAttempt;
string UserIDs[3][2] = { {"threem", "ashdsfhd"}, {"Daniel", "<ysdfhydfh"}, {"L3v1n", "BlaBlaBla"} };
cout << "Please enter your UserID" << endl;
cout << "UserID: ";
cin >> UserIDAttempt;
if (UserIDAttempt.compare (UserIDs[0][1]) == 0)
{
cout << "Hello " << UserIDAttempt << " please enter your Password" << endl;
cout << "Password: ";
cin >> PasswordAttempt;
if (PasswordAttempt.compare (UserIDs[0][2]) == 0)
{
cout << "Welcome " << UserIDAttempt << " have a pleasent stay" << endl;
}
else
{
cout << "Thats the wrong password" << endl;
}
}
else
{
cout << "Sorry " << UserIDAttempt << " it seems that you are not registerd" << endl;
}
}

Das hier ist mein bisheriger code Aber die attemps vergleichen sich nicht wirklich selbst wenn ich etwas falsches eingebe führt es weiter hin das richtige aus.

Jetzt selbst wenn ich die richtigen login daten eingebe sagt es mir das ich nicht registriet bin
 
Zuletzt bearbeitet:
http://www.cplusplus.com/reference/string/string/compare/ schrieb:
Return Value
Returns a signed integral indicating the relation between the strings:

valuerelation between compared string and comparing string
0They compare equal
<0Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
>0Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.
Das nächste Mal bitte Code-Tags nutzen.
 
  • Gefällt mir
Reaktionen: threem
Die UserIDAttemp würde ich in einer for Schleife durchlaufen und sofern es einen Treffer gibt diese in einer boolschen Variable merken. Strings vergleicht man mit equals.
 
  • Gefällt mir
Reaktionen: threem
Sorry das ich keine tags rein gepackt habe. Danke sehr für die schnellen antworten, da ich erst vor ein paar tagen mit c++ angefangen sagt mir der name for loop noch nicht so viel trotzdem danke :)
 
UserIDs[0][2] ist nicht das was du möchtest, weil es nur UserIDs[0][0] und UserIDs[0][1] gibt und {"threem", "Schnuffel3000"} entspricht.
 
  • Gefällt mir
Reaktionen: threem
Danke sehr für die hilfe und muss ich das mit dem Briefkasten verstehen oder ist das nicht so wichtig? lol
 
Anspielung auf die ganzen BriefkastenFirmen und Selbstständigen Steuerhinterzieher ;)
(wovon ich mich aber ausdrücklich distanziere ;) )
 
Zurück
Oben