在Windows

时间:2016-07-01 04:49:57

标签: c++ linux g++

我有一个程序显示不同的打印(在Windows上额外的0),我试图使它与Linux相同。 在使用Visual Studio 2012的Windows上。在linux上使用g ++ v4.8.3

任何sugegstion。

我创建了一个小程序来展示我面临的问题......

#include "stdafx.h"

#include <stdio.h>

int main()
{

 float f = -1e-14;
 printf("\n\n  \t Lets print the float value  -1e-14  as  [%9.3g]  \n\n\n\n",f);  

return 0;
}

在linux上:

/home/mag>./a.out


         Lets print the float value  -1e-14  as  [   -1e-14]

在Windows上:(在-1e-014注意额外的0)

         Lets print the float value  -1e-14  as  [  -1e-014]

我试图让它变得相同的原因是因为我正在调试来自windows和linux的一些输出,并且windows和linux的输出之间的巨大差异是由于上面提到的问题而我因为这些而缺少重要的差异。

1 个答案:

答案 0 :(得分:3)

首先致电_set_output_format(_TWO_DIGIT_EXPONENT),让printf()使用VS2012的两位数指数。

相关问题