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

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
BenderBendingRodriguez
New poster
Posts: 13
Joined: Wed Sep 08, 2004 10:54 am

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

Post 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
Last edited by BenderBendingRodriguez on Sat Sep 11, 2004 7:13 pm, edited 1 time in total.
When you do things right, people won't be sure you've done anything at all.
CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

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

Post 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
BenderBendingRodriguez
New poster
Posts: 13
Joined: Wed Sep 08, 2004 10:54 am

thx

Post by BenderBendingRodriguez »

thanks, that explains a lot. :)

Bender
When you do things right, people won't be sure you've done anything at all.
Post Reply

Return to “C++”