characters, to many in contsant?

This is a discussion on characters, to many in contsant? within the C++ Programming forums, part of the General Programming Boards category; I am trying to run a program wiht characters and an else if ladder, this is what i tried to ...

  1. #1
    hudy23
    Guest

    characters, to many in contsant?

    I am trying to run a program wiht characters and an else if ladder,
    this is what i tried to run and it gave me an error of too many characters in constant.
    What is wrong with it?
    p.s. i am a new programmer, be gentle.


    #include <iostream.h>
    int main ()
    {
    char name;
    cout<<"Enter your name:";
    cin>>clas;

    if (name == 'luke')
    cout<<"hello"<<endl;
    return 0;
    }

  2. #2
    Unregistered
    Guest
    my fault the program should look like this
    #include <iostream.h>
    int main ()
    {
    char name;
    cout<<"Enter your name:";
    cin>>name;

    if (name == 'luke')
    cout<<"hello"<<endl;
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    3
    A char can only be a single character, say 'a' or '5'.
    For that program, use a string, which you could think of as simply a sequence of char's, such as luke.

    To use strings (I use MS Visual, I don't know about other compilers), you #include <string>, and also add in 'using namespace std', without the 's before your program starts.
    The type is string, and for assignment, equality, and whatever else, you use double quotes. Hope this helps.

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    You can also read lesson 9 (character arrays and strings) here on the site.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 08:35 AM
  3. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  4. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 07:05 AM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM

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