Use these methods to read strings (for example, a line at a time) from the input stream:
The remaining arguments limit how much to read: up to `len-1' characters, or up to (but not including) the first occurrence in the input of a particular delimiter character delim---newline (\n ) by default. (Naturally, if the stream reaches end of file first, that too will terminate reading.)
If delim was present in the input, it remains available as if unread; to discard it instead, see iostream::getline .
get writes `\0' at the end of the string, regardless of which condition terminates the read.
streambuf object sb. Copying ends either just before the next instance of the delimiter character delim (newline \n by default), or when either stream ends. If delim was present in the input, it remains available as if unread.
char* , unsigned char* , or signed char* .
The remaining arguments limit how much to read: up to (but not including) the first occurrence in the input of a line delimiter character delim---newline (\n ) by default, or up to `len-1' characters (or to end of file, if that happens sooner).
If getline succeeds in reading a ``full line'', it also discards the trailing delimiter character from the input stream. (To preserve it as available input, see the similar form of iostream::get .)
If delim was not found before len characters or end of file, getline sets the ios::fail flag, as well as the ios::eof flag if appropriate.
getline writes a null character at the end of the string, regardless of which condition terminates the read.
pointer may be of type char* , void* , unsigned char* , or signed char* .
If the istream ends before reading len bytes, read sets the ios::fail flag.
\n by default).
To permit reading a string of arbitrary length, gets allocates whatever memory is required. Notice that the first argument s is an address to record a character pointer, rather than the pointer itself.
fscanf(file, format, ...) . The format is a scanf -style format control string, which is used to read the variables in the remainder of the argument list from the istream .
istream::scan , but takes a single va_list argument.