I want to compare u.username (user input) to the strings in my text file names.txt.
My understanding of the code I implemented:
1) I made a string u.username to take the user input
2) I created a variable string temp to store the strings coming from names.txt
3) I compared the two
4) in the instance the input matches (!=0) the program will output dou.
If its not too much to ask i'd prefer my code being fixed and then the fixes being explained. It's easier for me to understand.
this is my text file names.txt
1 2 3 4
qwerty
yesyes
pop
rin
this is my user class
1 2 3 4 5 6 7 8
class user {
public:
string username;
int pass;
string maiden;
char choice1;
fstream usernames;
};
int main() {
user u;
string temp;
cout<<"\nAre you a new user? (y/n)";
cin>>u.choice1;
if (u.choice1 == 'y')
{
cout<<"please enter your username: ";
getline (cin,u.username); //userinput
//open file to read
u.usernames.open("names.txt");
while(u.usernames>>temp){
if(temp.compare(u.username)!=0){
cout<<"dou";
}
}
u.usernames.close();
//closing the file
}