如题所述
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;
}
例如 读 文本文件 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;
}
温馨提示:答案为网友推荐,仅供参考