c++ - Str.compare() or (string)A == (string)B for string comparison -
i writing compiler reads file line line, checks line command (eg. d=am), splits substring , finds out each command was.
should using str.compare() or can use if statement below?
tempstring = line.find("=", line.length()); if(tempstring == "am"){return 65526;}
there doesn't seem of difference between 2 except using == return bool, while using str.compare() return int (specifically 0 if true, need use if(str.compare(str2) == 0) ). can see more compare function @ http://www.cplusplus.com/reference/string/string/compare/ .
Comments
Post a Comment