getchar. McGraw-Hill The Complete Reference Fourth Edition
広告
広告
710
C + + : T h e C o m p l e t e R e f e r e n c e
getchar
#include <cstdio> int getchar(void);
The getchar( ) function returns the next character from stdin. The character is read as an unsigned char that is converted to an integer.
If the end of the file is reached, getchar( ) returns EOF. If getchar( ) encounters an error, EOF is also returned.
The getchar( ) function is often implemented as a macro.
Related functions are fputc( ), fgetc( ), putc( ), and fopen( ).
gets
#include <cstdio> char *gets(char * str);
The gets( ) function reads characters from stdin and places them into the character array pointed to by str. Characters are read until a newline or an EOF is received. The newline character is not made part of the string; instead, it is translated into a null to terminate the string.
If successful, gets( ) returns str; a null pointer is returned upon failure. If a read error occurs, the contents of the array pointed to by str are indeterminate. Because a null pointer will be returned when either an error has occurred or when the end of the file is reached, you should use feof( ) or ferror( ) to determine what has actually happened.
There is no way to limit the number of characters that gets( ) will read, and it is possible for the array pointed to by str to be overrun. Thus, gets( ) is inherently dangerous.
Related functions are fputs( ), fgetc( ), fgets( ), and puts( ).
perror
#include <cstdio> void perror(const char * str);
ダウンロード
広告