IStream & IStream:: Get (char *, int, char = ' \ n ');
IStream & IStream:: Getline (char *, int, char = ' \ n ');
Function: Extracts the specified number of characters from the text and adds a null character at the end of the string array
Where the first argument points to a character array that accepts character data
The second parameter specifies the maximum number of characters that a character array can hold
The third parameter is used to specify a terminator, which is the default line break character
The extraction terminates when the operation encounters a terminator or extracts to a specified number character
Difference: Get () does not extract the terminating character from the stream, and the terminating character is still in the input stream
Getline () extracts the terminating character from the stream, but the terminating character is discarded
1#include <iostream>2 using namespacestd;3 intMain ()4{CharBUF [ the ] ;5Cin.Get(BUF, the,'y') ;//specifying a terminating character6cout << buf << Endl;//default terminator ' \ n '7Cin.Get(BUF, the ) ; 8cout << buf <<Endl;9Cin.getline (BUF, the,'N' ) ;Tencout << buf <<Endl; OneCin.Get(BUF, the ) ; Acout << buf <<Endl; - return 0; -}
1#include <iostream>2#include <fstream>3 using namespacestd;4 intMain ()5{Ifstream inf ("d:\\testnew" ) ; 6 CharBUF [ the ] ;7Inf.getline (BUF, the ) ; 8cout << buf <<"____"<< Inf.gcount () <<Endl;9On.Get(BUF, the ) ; Tencout << buf <<"____"<< Inf.gcount () <<Endl; One inf.close (); A}
C + + Extract text data from a standard stream