How can I take input from a user and compare it with data on a file?
Myfile.txt contains the following Data
Louise Ravel
Raven
Wings
Crosses and Bridges
Bjarne
In my Program
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream file("Myfile.txt");
std::string name;
std::cout<<"Enter the name to compare with the data: ";
std::getline(std::cin,name);
return 0;
}
Now once the user enters the input, I want to compare the string entered with the data available in MyFile.txt and if a matching string is found then just simply print "Match Found"
I tried this one but it didn't work.
while(file>>name)
{
if(file==name)
{
cout<<"Match Found";
}
}
How can I do that?
while(file>>name) { if(file==name) { cout<<"Match Found"; } }but it didn't work