I have written the following code to read the text line by line :
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream fin; // input and
ofstream fout; // output
string line; // syntax.
char filename[512];
cout << "Enter the absolute path to the file:";
cin >> filename;
fin.open(filename);
if ( fin.fail() ) {
cerr << "Could not open file " << filename << endl;
exit(1);
}
while (std::getline(fin, line)){
if((line[0] == "H" && line[1] == "E" && line[2] == "T" && line[3] == "A" && line[4] == "T" && line[5] == "M") ||
(line[0] == "A" && line[1] == "T" && line[2] == "O" && line[3] == "M"))
cout << "hello" << endl;
}
}
But the code displays the following error :
warning: comparison with string literal results in unspecified behaviour [-Waddress]|
error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
for the if statement.
How do I get past this error? In addition to this, it would be very kind of you if you could tell me how can I read files with format .pdb and not .txt. If .pdb is openable in notepad if forced to.