Page 1 of 1

'Single-Quotes' and "Double-Quotes" ...?

Posted: Wed Sep 08, 2004 11:40 am
by BenderBendingRodriguez
hi, i am new to this board and to the judge, but i'm also interested for solving some problems.

so, i have a question about 'Single-Quotes' and "Double-Quotes" in C++..
what is the difference between 'Single-Quotes' and "Double-Quotes" ...?

if my code looks like this:

Code: Select all

 char c;
... // c is an character, for example 'a'
if(c == "\n")
{ ...
...i get an ErrorMessage like this while compiling: "cannot compare char-pointer with constant string"

then i use the 'Single-Qutes' instead so that the one line looks like this:

Code: Select all

if(c == '\n')
...and there is no problem.

what is the exactly difference between 'Single-Quotes' and "Double-Quotes" ...?


Bender

Re: 'Single-Quotes' and "Double-Quotes" ...?

Posted: Wed Sep 08, 2004 11:52 am
by CDiMa
BenderBendingRodriguez wrote:what is the difference between 'Single-Quotes' and "Double-Quotes" ...?
Single-quotes are used to specify character constants while double quotes specify string constants. So the behaviour of your compiler is exactly what should be expected :)

Ciao!!!

Claudio

thx

Posted: Wed Sep 08, 2004 12:03 pm
by BenderBendingRodriguez
thanks, that explains a lot. :)

Bender