_set_output_format_set_output_format

自定义格式化 I/O 函数使用的输出格式。Customizes output formats used by formatted I/O functions.

重要

此函数已过时。This function is obsolete. 从 Visual Studio 2015 开始,CRT 中不再提供此函数。Beginning in Visual Studio 2015, it is not available in the CRT.

语法Syntax

unsigned int _set_output_format(  
   unsigned int format  
);  

参数Parameters

[in] format[in] format
表示要使用的格式的值。An value representing the format to use.

返回值Return value

以前的输出格式。The previous output format.

备注Remarks

_set_output_format 用于配置格式化 I/O 函数的输出,如 printf_s_set_output_format is used to configure the output of formatted I/O functions such as printf_s. 目前,此函数可以更改的唯一格式设置约定是输出浮点数时在指数中显示的位数。At present, the only formatting convention that can be changed by this function is the number of digits displayed in exponents in the output of floating point numbers.

默认情况下,即使不需要使用三位数来表示指数的值,由函数(例如 printf_swprintf_s等)和 Visual C++ 标准 C 库中的相关函数输出浮点数也会打印表示指数值的三位数。By default, the output of floating point numbers by functions such as printf_s, wprintf_s, and related functions in the Visual C++ Standard C library prints three digits for the exponent, even if three digits are not required to represent the value of the exponent. 用零来填充此值,使其成为三位数。Zeroes are used to pad the value to three digits. 利用_set_output_format 可以更改此行为,这样就可以只打印指数中的两位数,除非指数的大小必需具有第三个数字。_set_output_format allows you to change this behavior so that only two digits are printed in the exponent unless a third digit is required by the size of the exponent.

若要启用两位数指数,请使用参数 _TWO_DIGIT_EXPONENT调用此函数,如示例中所示。To enable two-digit exponents, call this function with the parameter _TWO_DIGIT_EXPONENT, as shown in the example. 若要禁用两位数指数,请使用参数 0 调用此函数。To disable two digit exponents, call this function with an argument of 0.

要求Requirements

例程Routine 必需的标头Required header
_set_output_format <stdio.h><stdio.h>

有关兼容性的详细信息,请参阅“简介”中的兼容性For more compatibility information, see Compatibility in the Introduction.

示例Example

// 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);  
}  
1.2110e-005 2.3056e-112  
1.2110E-005 2.3056E-112  
 1.211e-005  2.306e-112  
 1.211E-005  2.306E-112  
 1.2110e-05 2.3056e-112  
 1.2110E-05 2.3056E-112  
  1.211e-05  2.306e-112  
  1.211E-05  2.306E-112  
1.2110e-005 2.3056e-112  
1.2110E-005 2.3056E-112  
 1.211e-005  2.306e-112  
 1.211E-005  2.306E-112  

另请参阅See Also

printf_s、_printf_s_l、wprintf_s、_wprintf_s_l printf_s, _printf_s_l, wprintf_s, _wprintf_s_l
_get_output_format_get_output_format