C++ で 2 つの文字列を比較しようとすると (1 つはファイルから読み込まれ、もう 1 つは値が割り当てられます)、正しくない出力が得られます。
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;
理論的には、これは、これら 2 つの文字列が正しいことを示す「true」を返す必要があります。temp = "P5" の出力なので、毎回 else の場合にヒットする理由がわかりません。どんな助けでも大歓迎です!