i'm a c++ beginner and i think that the c++ compiler notices the difference between single and double quotation marks (unlike the other languages i know).
when i try something like
if(ch=="Q") { cout %26lt;%26lt; "true"; }
it tells me that there's an error so i replace the quotation marks around the Q to be
if(ch=='Q'){ cout %26lt;%26lt; "true"; }
and it works fine. why is that?
In c++, what is the difference between single and double quotation marks?
usually the ' is for type char and " is for type string. if ch is char in your example you get an error because "Q" is different in type from 'Q'. 'Q' is a char so if char(ch)==char is evaluated but "Q" is string and char(ch)==string returns an error (invalid type).
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment