Apostrophe (Think thats spelt right.)

This is a discussion on Apostrophe (Think thats spelt right.) within the C++ Programming forums, part of the General Programming Boards category; Hi again. How would I say : Code: If character equals apostrophe : Quick example : Code: #include <iostream> #include ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    Apostrophe (Think thats spelt right.)

    Hi again.

    How would I say :

    Code:
    If character equals apostrophe :
    Quick example :

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main ()
    {
            char character;
    
            if ( character == ''' )
            {
                    cout<<"This wouldn't work. Plz help.";
            }
    
    }
    See what I mean ? Three apostrophies wouldn't work.
    Any advice anyone can give me ?

    Cheers
    Last edited by Necrofear; 05-15-2006 at 02:19 PM.

  2. #2
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    Quote Originally Posted by Necrofear
    Hi again.

    How would I say :

    Code:
    If character equals apostrophe :
    Quick example :

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main ()
    {
            char character;
    
            if ( char = ''' )
            {
                    cout<<"This wouldn't work. Plz help.";
            }
    
    }
    See what I mean ? Three apostrophies wouldn't work.
    Any advice anyone can give me ?

    Cheers
    for starters your if statement is wrong

    you don't check variable character which is what i think you wanted to do, instead you just put char

    you also did should have used == rather then the assignment operator

    just quick mistakes you made, hopefully

    anyway here is the solution:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
       char a = '\'';
       
       if(a == '\'')
       {
          cout<< "hey it worked";
       }
       else
       {
          cout<< "it didn't work";
       }
       cin.ignore();
    }

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    If I remember, this would be correct:
    Code:
    if(c == '\'')

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Oh yeah. Sorry I was in a rush, an didn't realize my mistake.
    Ta for the replies.

    EDIT : Changed the if statement conditions.

  5. #5
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    This will be an issue for a number of characters: double quotes, backslashes, etc. Look up escape sequences.
    There is a difference between tedious and difficult.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    What about the F keys ?
    (I think I've asked about them before.)

    If I put :

    Code:
    ch = getch();
    cout<<ch;
    Every time I hit an F key, a character, or multiple characters are displayed. Is there a way to stop this from happening.
    Last edited by Necrofear; 05-15-2006 at 03:30 PM.

  7. #7
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Quote Originally Posted by Necrofear
    What about the F keys ?
    (I think I've asked about them before.)

    If I put :

    Code:
    ch = getch();
    cout<<ch;
    Every time I hit an F key, a character, or multiple characters are displayed. Is there a way to stop this from happening.
    Yeah. Stop entering F-keys

    Code:
    ch = getch();
    if (ch == '\0')    // A special key was entered
    {
        ch = getch();  // read the function character
    }
    else
    {
        cout << ch;    // display if not a function character
    }
    Special keys include Fx keys, Arrows, End, Home, etc.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    I used that method, but it only worked for F 1 - 10.
    Is it not meant to include F 11 and 12 ?

    Ta

Popular pages Recent additions subscribe to a feed

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