I m currently stuck in a very simple problem ,this code is part of my programme it takes data from the user and then reads the data from the file(that contains the name of the movies and actors) and compare it with input but it gives wrong result.This is my code
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
string name;
getline(cin, name);
string compare;
ifstream myfile;
myfile.open("movie.txt");
bool found = false;
if (myfile.is_open())
{
while (getline(myfile, compare))
{
if (compare == name)
{
cout << "record found" << endl;
found = true;
}
}
myfile.close();
}
if (found)
cout << "not found" << endl;
}
Any help regarding this would be appreciated . Thanks