how do i print a "

This is a discussion on how do i print a " within the C++ Programming forums, part of the General Programming Boards category; how do i print the character the character "...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    how do i print a "

    how do i print the character the character "

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Use an escape sequence:

    Code:
    \"
    In other words:

    Code:
       std::cout << "This sentence uses two \"escape sequences\"" << std::endl;
    Last edited by kermit; 12-30-2005 at 02:39 PM.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    You don't have to escape the double quote if it's in single quotes:
    Code:
    cout << '"' << "Ouch!" << '"' << ", he said.\n";
    cout << "\"Ouch!\", he said.\n";
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Here's a list of them all:

    Escape Sequence Description

    \' Single quote
    \" Double quote
    \\ Backslash
    \0 Null character
    \a Audible bell
    \b Backspace
    \f Formfeed
    \n Newline
    \r Carriage return
    \t Horizontal tab
    \v Vertical tab
    \xnnn Hexadecimal number (nnn)

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    And '\?' in C. ('\?' is the same as '?'; it's included to break up potential trigraphs.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21