std::fgetc
STD::fgetc,std::getc
Defined in header | | |
---|---|---|
int fgetc( std::FILE* stream int getc( std::FILE* stream | | |
从给定的输入流读取下一个字符。
参数
stream | - | to read the character from |
---|
返回值
在成功或成功时获得的性格EOF
在失败的时候。
如果故障是由文件结束条件造成的,则另外设置EOF
指标%28见std::feof()
29%stream
如果故障是由其他错误引起的,则设置误差
指标%28见std::ferror()
29%stream
...
例
二次
#include <cstdio>
#include <cstdlib>
int main()
{
FILE* fp = std::fopen("test.txt", "r"
if(!fp) {
std::perror("File opening failed"
return EXIT_FAILURE;
}
int c; // note: int, not char, required to handle EOF
while ((c = std::fgetc(fp)) != EOF) { // standard C I/O file reading loop
std::putchar(c
}
if (std::ferror(fp))
std::puts("I/O error when reading"
else if (std::feof(fp))
std::puts("End of file reached successfully"
std::fclose(fp
}
二次
另见
gets (until C++14) | reads a character string from stdin (function) |
---|---|
fputcputc | writes a character to a file stream (function) |
ungetc | puts a character back into a file stream (function) |
c fgetc,getc的文档
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。