_set_output_format

自訂格式化 I/O 函式所使用的輸出格式。

重要

此函式已過時。 自 Visual Studio 2015 起,此函式即無法在 CRT 中使用。

語法

unsigned int _set_output_format(
   unsigned int format
);

參數

format
[in] 值,代表要使用的格式。

傳回值

舊的輸出格式。

備註

_set_output_format 是用來設定格式化 I/O 函式的輸出,例如 printf_s 。 此函式唯一可以變更的格式慣例,就是浮點數輸出中以指數顯示的位數。

根據預設,Visual C++ Standard C 程式庫中的浮點數輸出會列印 printf_swprintf_s 三位數的指數,即使不需要三位數來表示指數的值也一樣。 零會用來將值填補到三位數。 _set_output_format 可用於變更此行為。除非指數大小需要第三位數,否則將會列印只有兩位數的指數。

若要啟用兩位數指數,請呼叫此函式並使用參數 _TWO_DIGIT_EXPONENT,如範例中所示。 若要停用兩位數指數,請呼叫此函式並使用引數 0。

需求

常式 必要的標頭
_set_output_format <stdio.h>

如需詳細的相容性資訊,請參閱簡介中的 Compatibility

範例

// 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

另請參閱

printf_s, _printf_s_l, wprintf_s, _wprintf_s_l
_get_output_format