Comparison of two strings in C++
When I attempt to compare two strings in C++ (one read in from a file, the
other assigned a value), I get an incorrect output:
ifstream pgmFile;
pgmFile.open(fileName);
string temp;
string comp = "P5";
for(int i = 0; i < 2; i++)
{
pgmFile >> noskipws >> temp;
cout << temp;
}
if(temp == comp)
{}
else
cout << "File does not contain 'P5'. Please provide the correct type
of file." << endl;
In theory this SHOULD return "true" that these two strings are correct.
The output for temp = "P5", so I don't understand why it hits my else case
every single time. Any help is much appreciated thanks!
No comments:
Post a Comment