cin.get() 和 cin.get(char)
- If you want a program to examine every character, you should use one of the get() methods. For example, a word-counting program could use white space to determine when a word came to an end. Of the two get() methods, the get (char &) has the classier interface. The main advantage
of the get() method is that it closely resembles the standard C getchar() function, which means you can covert a C program to a C++ program by including iostream instead of stdio.h, globally replacing getchar() with cin.get(), and globally replacing C’s putchar(ch) with cout.put(ch). - If skipping white space is convenient, you should use the extraction operator, >>.
String Input: getline(), get (), and ignore()
istream & get(char *, int ,char);
istream &get(char *, int)
istream & getline(char* , int,char);
istream & getline(char*,int );
char line[50];
cin.get(line,50);
The cin.get() function quits reading input into the array after encountering 49 characters or, by default, after encountering a newline character, whichever comes first.
The chief difference between get() and get getline() is that get() leaves the newline character in the input stream, making it the first character seen by the next input operation, whereas getline() extracts and discards the newline character from the input stream.