vendredi 6 novembre 2020

string.compare() function not comparing the correct string

Unsure why, but when I am using string::compare() in my code, it is printing the opposing switch statement, rather than the one it is supposed to.

cout<<lexeme << " ";
if(lexeme.compare("begin")){
   item = LexItem(BEGIN, "begin", linenum);
   return item;
}
if(lexeme.compare("print")){
   item = LexItem(PRINT, "print", linenum);
   return item;
}

I cout the string before I begin to compare, and even though it prints the correct string, it returns the "print" compare rather than the "begin":

begin PRINT print 1

Has anyone run into this problem, or knows why it would be doing this?

Aucun commentaire:

Enregistrer un commentaire