c/cpp IO
c中读取输出
单个字符
int fgetc( FILE *stream );
int fputc( int ch, FILE *stream );
int ungetc( int ch, FILE *stream );
int scanf( const char* format, ... )
int fscanf( std::FILE* stream, const char* format, ... )
int sscanf( const char* buffer, const char* format, ... )
返回读取的参数的数量, or EOF The conversion specifiers that do not consume leading whitespace: %c、%[、%n一串字符
char *fgets( char *restrict str, int count, FILE *restrict stream );
读取count-1个字符(一个用于存储'\0'__ null-terminated), parse stop when end-of-file or a newline found; it contain the newline character if success: return str; if error: return NULLint fputs( const char *restrict str, FILE *restrict stream );
unix最大打开文件数
#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
c++中读取输出
一串字符
std::basic_istream<CharT,Traits>& std::getline(std::basic_istream<CharT,Traits>& input, std::basic_string<CharT,Traits,Allocator>& str, CharT delim )
读取字符存到str, parse stop when end-of-file or delim found; extract the delim character, but not contain the delim character单个字符
char c; cin >> c
cin.ignore(ignore_num, delim)
Extracts and discards characters from the input stream until and including delimcin mixed with getline >> input: 2 request=10 release=20
when used cin >> n, then getline(cin, str), because of getline will not consume the delimter left by cin 1
2
3
4cin >> n
- cin >> std::ws //removing left whitespace
- cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n') //ingore all left over characters on the line
- getline(cin, notusestr); // explicit remove the newline charactor