_set_output_format
自定义格式化的 I/O 函数使用的输出格式。
unsigned int _set_output_format(
unsigned int format
);
参数
- [in] format
表示格式的值。
返回值
前面的输出格式。
备注
_set_output_format 用于配置格式化 I/O 函数输出 (如 printf_s。 当前,此函数可以由更改的格式约定是在浮点数的指数输出显示的数字位数。
默认情况下,只有浮点输出因函数计算,如 printf_s、wprintf_s,并且,相关函数。Visual C++ 标准 C 库中打印指数的三位数字,因此,即使没有要求三位数字表示指数的值。 填零用于填充值为三位数。 使用_set_output_format 可以更改此行为,以便仅在两位数指数打印,除非第三位数由指数大小的需要。
如示例中所示,若要启用双字节指数中,使用参数调用 _TWO_DIGIT_EXPONENT的函数,此。 若要禁用两位数指数中,使用参数调用此函数的 0。
要求
例程 |
必需的标头 |
---|---|
_set_output_format |
<stdio.h> |
有关更多兼容性信息,请参见“简介”中的兼容性。
.NET Framework 等效项
不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见平台调用示例。
示例
// crt_set_output_format.c
#include <stdio.h>
void printvalues(double x, double y)
{
printf_s("%11.4e %11.4e\n", x, y);
printf_s("%11.4E %11.4E\n", x, y);
printf_s("%11.4g %11.4g\n", x, y);
printf_s("%11.4G %11.4G\n", x, y);
}
int main()
{
double x = 1.211E-5;
double y = 2.3056E-112;
unsigned int old_exponent_format;
// Use the default format
printvalues(x, y);
// Enable two-digit exponent format
old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
printvalues(x, y);
// Disable two-digit exponent format
_set_output_format( old_exponent_format );
printvalues(x, y);
}