I'm doing a string comparison but there is a problem. I have a file in which 12345
is written and then I have made another source file and performed input (input is 12345
). Then I'm comparing it through bool
true
false
logic but the issue is that the bool
never gets true and I think that there is a logical error in the comparison but I didn't get what's wrong in it.
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;
int
main()
{
char str[256];
char CNIC[5];
std::fstream file1;
for(int i = 0; i < 5; i++)
{
CNIC[i] = getche(); // editor's comment: probably std::getchar()
}
file1.open("D:\\UOL\\OoP\\Nadra database.txt", ios::in);
bool check = false;
while(!file1.eof())
{
file1.getline(str, 255);
if(str == CNIC)
{
check = true;
break;
}
if(check)
{
cout << endl << "CNIC number matched" << endl;
}
else
{
cout << endl << "CNIC number didn't match" << endl;
}
}
file1.close();
system("pause");
return 0;
}