cin.get

whats the difference between cin.get(char) and cin>> char?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main()
{
    char c ;

    std::cin >> c ; // gets the next non-whitespace char (discards leading whitespaces)

    std::cin.get(c) ; // gets the next char (which may be a white space)

    std::cin >> std::noskipws ;
    std::cin >> c ; // gets the next char (which may be a white space)
}
ok and whats cin.putback(ch)?
closed account (j2NvC542)
That's pretty self explanatory, don't you think? Puts a character back to the istream so you can read it again (you might want to read it into another data type).
With the caveat: what is guaranteed by the standard is that we can putback one character after a succesfull read of that character.

Topic archived. No new replies allowed.