I am currently learning about file handling in c++. I want to check if the username that the user has entered in the beginning is the same as the one he enters in the end to write to a TXT file.
I tried running a loop and comparing the char array at index [0] with the string index[0].
code explaination: getuser - username entered in the beginning (String)
user - username entered now (char array)
char user[16];
for(int i = 0; i < getUser.length(); i++){
if(!(user[i] == getUser[i])){
cout << "enter right username!";
exit(1);
}
}
I wanted the loop to check each character, if it right, it will continue, otherwise it will print an error message and exit with return 1.
Aucun commentaire:
Enregistrer un commentaire