Thread: variables

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    Post variables

    plz i need to know all variables especially the variable for text i knoe CHAR but it only displays 1 letter plz email me with the answer
    me

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    Do you mean functions to display text? or declaring variables that hold strings?

  3. #3
    Registered User Casey's Avatar
    Join Date
    Jun 2003
    Posts
    47
    bool
    char (signed or unsigned)
    short (signed or unsigned)
    int (signed or unsigned)
    long (signed or unsigned)
    float
    double
    long double

    For text you use either an array of char or the string class offered by the standard library in the <string> header.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    To display more than one character you use an array of char, thus...

    char x; // single character
    char y[10]; // array for 9 character string

    ... a string like this must have a NULL character as it terminator, so the array must always be one character longer than the string you wish to show.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    Lightbulb space

    it dn display spaces like of i use
    #include <iostream.h>
    int main()
    {
    cout<<"Welcome to shady's first c++ program\n";
    char name[90];
    cout<<"wut's ur name?\n";
    cin>>name;
    cout<<"Welcome "<<name<<"\n";
    }
    and type name secondname third name it only displays the name


    Originally posted by adrianxw
    To display more than one character you use an array of char, thus...

    char x; // single character
    char y[10]; // array for 9 character string

    ... a string like this must have a NULL character as it terminator, so the array must always be one character longer than the string you wish to show.

  6. #6
    Registered User Casey's Avatar
    Join Date
    Jun 2003
    Posts
    47
    cin's >> operator stops reading at spaces. If you want to have whitespace in your input you can use getline
    Code:
    cin.getline(name, sizeof (name));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Replies: 6
    Last Post: 01-02-2004, 01:01 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 02:39 PM