用fgets函数读文件
#include<stdio.h>
#include<cstring>
int main(){
char str[20];
FILE *fp = fopen("D:/1.txt","r");
if(fp==NULL){
perror("fopen");
return -1;
}
while(feof(fp)==0){
fgets(str,sizeof(str),fp);
printf("%s",str);
}
fclose(fp);
fp=NULL;
return 0;
}