How do I do this?

This is a discussion on How do I do this? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by SlyMaelstrom It doesn't store 22 letters. Those are currently in your buffer. In this case I/O stream ...

  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,662
    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?

Page 2 of 2 FirstFirst 12
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