64,654
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<fstream>
#include<strstream>
#include<cmath>
#include<string>
#include <cstring>
#include <stdio.h>
using std::endl;
using std::cin;
using std::cout;
using std::string;
using namespace std;
int main()
{
FILE *fp, *fp1;
int i, j;
char str1[100];
char strchar1[3];
if ((fp1 = fopen("1.txt", "r")) == NULL)
{
printf("fopen() error %d: %s\n", errno, strerror(errno));
exit(-1);
}
// str1[strlen(str1)] = '\0';
// for (i = 0; i <= 100; i++)
// {
while (fgets(str1, sizeof(str1), fp1)) //fgets会自动为str1添加结尾符‘\0’
{
cout << str1;
}
return 0;
//}
}