c++ 如何把数组数据写入文件

最好用 fprintf
2024-11-08 15:14:54
推荐回答(1个)
回答1:

帮你写了个简单的你看看就知道怎么写入了:)

#include"stdio.h"
#define MAX 1000
main()
{FILE *fp;
int
i=0;
char sky[MAX];
printf("please
input:\n>>");
gets(sky);
fp=fopen("001.txt","w");
while(sky[i]!='\0'
)
{fprintf(fp,"%c",sky[i]);
i++;
}
;
fclose(fp);
printf("write over!");
getch();

}