使用C++实现保存txt文件
发布时间:2023-05-17 20:10:11
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char filename[50];
char content[1000];
printf("请输入要保存的文件名:
");
scanf("%s", filename);
printf("请输入要保存的内容:
");
scanf("
");
// 读取用户输入的内容
fgets(content, 1000, stdin);
// 打开文件
FILE *fp = fopen(filename, "w");
// 写入内容
fprintf(fp, "%s", content);
// 关闭文件
fclose(fp);
printf("文件保存成功!
");
return 0;
}
