0

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

user4581301
  • 33,082
  • 7
  • 33
  • 54
  • Can you provide an example user input and an example line from the file being checked? – ShadowRanger Sep 30 '15 at 03:13
  • None of the usual howlers in the code. Only problem I can spot right off is not opening the file outputs "not found". Probably should handle that with an else and a `cout << "file not open" < – user4581301 Sep 30 '15 at 03:17
  • first line of the file contains name Bilitis (1977) , if the user enters the same name the output should be record found but it wont.@ShadowRanger – Mohsin Mushtaq Sep 30 '15 at 03:19
  • i checked it and also what is present in compare variable and name it gives same output but on comparison dont give right result.@user4581301 – Mohsin Mushtaq Sep 30 '15 at 03:23

1 Answers1

0

For debug you can use string_to_hex from here on both compare and name

Community
  • 1
  • 1
noonex
  • 1,975
  • 1
  • 16
  • 18