References:
Http://blog.163.com/huang_zhong_yuan/blog/static/1749752832010102223333176/
The get function can obtain a single character, a specified length string, and so on each time.
The Getline function obtains a row each time, or extracts strings separated by specified delimiters.
Get function prototype:
int get();istream& get ( char& c );istream& get ( char* s, streamsize n );istream& get ( char* s, streamsize n, char delim );istream& get ( streambuf& sb);istream& get ( streambuf& sb, char delim );
Http://www.cplusplus.com/reference/iostream/istream/get/
Getline function prototype:
istream& getline (char* s, streamsize n );istream& getline (char* s, streamsize n, char delim );
Http://www.cplusplus.com/reference/iostream/istream/getline/
We can see that both functions can extract strings Based on the specified delimiter.
Differences:
When the get function encounters a delimiter, it stops obtaining the delimiter and leaves it in the input stream. When the Getline function encounters a delimiter, it stops obtaining the delimiter, but extracts it from the input stream.
Therefore, when using the get function, you need to manually skip the delimiter, while Getline does not.
Sample Code:
# Include <iostream> # include <string> # include <sstream> int main () {int length; STD: String ST = "enter, the, name, of,, existing, text, file: "; STD: istringstream (ST); int I = 0; char array [20] = {0}; while (stream. get (array, 20, ',') {// get the current position length = stream. tellg (); STD: cout <array <STD: Endl; // skip the comma (,) stream. seekg (Length + 1, STD: IOS: Beg);} return 0 ;}