Question: C++ Comparing user input to string array I have a text file with first first names and last names in rows like this: John Smith
C++ Comparing user input to string array
I have a text file with first first names and last names in rows like this:
John Smith
Jaden Smith
Will Smith
Now I saved these files into a string array using a forloop to go till the end of file with "getline(inputfile, userName[i]); // Reads name"
Now I want the user to enter a name, I tried using "getline(cin, userInput);" and look through the array if that name is there.
The problem is although I'm entering a valid name, it never matches. So even though userName[0] is "John Smith" and userInput is entered as "John Smith", when I compare it, its never true via the comparison operator "=="
Example:
if(userName[0] == userInput) {
cout << "Match" << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
