Checking for ' in an if

This is a discussion on Checking for ' in an if within the C++ Programming forums, part of the General Programming Boards category; Hello all; Having a brain fart here. I want to check if a char is == to an ' or ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    85

    Checking for ' in an if

    Hello all;

    Having a brain fart here.

    I want to check if a char is == to an ' or not.


    the statement if(char == ''') does not work bc the compiler sees the second ' as the end and the third as erroneous. Sooo....

    how can I test for this condition

  2. #2
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    Escape sequences.

    Use the escape sequence for a single quote ( \' ) inside your quotes.

    Code:
    if (x == '\'')
    ...
    Last edited by Decrypt; 06-30-2006 at 07:33 AM.
    There is a difference between tedious and difficult.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,745
    escape with a backslash, e.g. '\''
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,553
    Use a \
    Code:
    '\''
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  3. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM
  4. wont write to variable
    By Klinerr1 in forum C++ Programming
    Replies: 3
    Last Post: 07-25-2002, 10:00 PM
  5. off the screen
    By Klinerr1 in forum C++ Programming
    Replies: 2
    Last Post: 07-23-2002, 08:47 PM

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