Thread: How do I do this?

  1. #16
    C++ beginner
    Join Date
    Jun 2004
    Posts
    66
    Quote Originally Posted by SlyMaelstrom
    It doesn't store 22 letters. Those are currently in your buffer. In this case I/O stream has done all the work up to this point. You just need to extract the first character from the string and put it into a variable.

    Code:
    cin >> ch;
    Now the 'I' is in the ch variable and the cin buffer has " enjoy a good slice of pie. #\n" in it. If you were to cin another character, you'd get the space.... and so on and so on until you get to the pound sign.
    I see, that makes a lot more sense. Thank you.
    Oh my goodness.

  2. #17
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Here is in an int variable:

    int num;

    Here is an assignment to that variable:

    num = 3;

    What is stored in 'num'?

    Here is another assignment:

    num = 5;

    What is stored in num? Is it 35? Or is it 5?

    Here is a char variable:

    char myChar;

    Here is an assignment to that variable:

    myChar = 'a';

    What is stored in myChar?

    Here is another assignment:

    myChar = 'b';

    What is stored in myChar? Is it "ab"? Or is it 'b'? Does a char variable work differently than an int variable?

Popular pages Recent additions subscribe to a feed