gpt4 book ai didi

c - fwprintf() "%ff"格式

转载 作者:行者123 更新时间:2023-11-30 19:19:48 27 4
gpt4 key购买 nike

我偶然发现了以下格式:

 fwprintf( file, "%ff" ,someFloat);

这是什么意思?我知道“%ll”是“long long”for example .但是%ff?它是 double float 吗?这样的格式对于 float 有任何实际意义吗?

最佳答案

%ff格式与%f格式相同,代表float,但第一个也会多写一个f。

[归功于奥利]

发生的情况是,格式被视为 %f,而第二个 f 被视为典型字符。

示例:

  float a = 1.2345678;
fprintf(stdout, "%f\n", a);
fprintf(stdout, "%ff\n", a);

输出:

1.234568
1.234568f

因此,对于fwprintf,您将在文件中写入冗余的f

这是一个例子:

#include <stdio.h>
#include <wchar.h>

int main(void)
{
float a = 1.23456;

const char *testFileName = "test.txt";
FILE *wideTestFile;
wideTestFile = fopen(testFileName, "w");
fwprintf( wideTestFile, L"Format ff: %ff\n" ,a);
fwprintf( wideTestFile, L"Format f: %f\n" ,a);

return 0;
}

test.txt包含:

Format ff: 1.234560f
Format f: 1.234560

关于c - fwprintf() "%ff"格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23721751/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com