2024-06-03 64
1.-------------------------------------------------------------------------------fprintf fprintf是C/C++中的一个格式化写—库函数;其作用是格式化输出到一个流/文件中 fprintf (stream//文件指针,format//输出的数据类型, [argument]//变量) #include #include #include FILE* stream; int main(void) { int i = 10; double fp = 1.5; char s[] = "this is a string"; char c = ''; stream = fopen("abc.txt", "w");//w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。 fprintf(stream, "%s%c", s, c);//把char s[] = "this is a string"; 和 char c = '';写入到abc.txt fprintf(stream, "%d", i);//把int i = 10;写入到abc.txt fprintf(stream, "%f", fp);//把double fp = 1.5;写入到abc.txt,输出为floast(%f)浮点型,小数点后面保留6位小数,不够补零 fclose(stream); system("abc.txt");//打开abc.txt return 0; }
原文链接:http://www.tpbz008.cn/post/56100.html
=========================================
http://www.tpbz008.cn/ 为 “电脑技术吧” 唯一官方服务平台,请勿相信其他任何渠道。
系统使用 2023-04-23
应用技巧 2023-07-01
电脑技术 2023-10-29
应用技巧 2023-11-14
应用技巧 2022-11-20
系统使用 2022-11-15
应用技巧 2023-03-09
系统使用 2022-11-21
应用技巧 2023-03-14
应用技巧 2023-02-14
扫码二维码
获取最新动态