若要从文本文件读取字符,可以使用哪个方法

如题所述

c/c++ 语言 用 fgetc。
例如 读 文本文件 abc.txt 并输出1个个字符到屏幕:
c++ 程序要 包含前面两行头文件
//#include<iostream>
//using namespace std;
#include<stdio.h>
int main()
{
FILE *fp;
int c;
fp=fopen("abc.txt","r");
if (!fp){ printf("open file error. \n"); return 1;};
do {
c = fgetc (fp);
printf("%c",c);
} while (c != EOF);
fclose (fp);

return 0;
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网