Thread: Tell me if I'm right-

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209

    Tell me if I'm right-

    I'm trying to recall all of the versions of std::cin and how they deal with string input. Please correct me if I'm wrong or if I'm missing any (I'm typing all of this from memory).

    cin>> reads chars into the variable or array. Terminates upon blank characters and throws away \n characters produced by the enter key. If it's an array, it adds the null character at the end.

    cin.get() reads a char from the input stream and returns it. Leaves the \n character in the input buffer.

    cin.get(ch) reads a char from the input stream and stores it in ch. Leaves the \n character in the input buffer.

    cin.get(chArray, 50) reads up to 50 characters from the input stream and stores them in chArray. Leaves the \n character in the input buffer. Puts the null character where the \n was.

    cin.getline(chArray, 50) reads up to 50 characters from the input stream and stores them in chArray. Reads and throws away the newline character. Puts the null character where the \n was.

    Please make any corrections necessary. I'm tired of not being able to correctly remember what all these do.
    Last edited by homeyg; 02-07-2005 at 09:54 PM.

Popular pages Recent additions subscribe to a feed