首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::getc

Defined in header <cstdio>

?

?

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...

二次

代码语言:javascript
复制
#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的文档

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com