我需要运行一个在 Linux 和 Visual Studio 上都有类似输出的程序。
Linux 的指数字段默认宽度为 2,而 Visual Studio 的默认宽度为 3。
因此,对于数字 3.40282e+38,Linux 保持原样,但 Visual Studio 会用额外的 0、3.40282e+038 填充它
有人知道如何在 Visual Studio 中配置输出以删除零吗? (或者在 Linux 中添加零)
最佳答案
根据维基百科:http://en.wikipedia.org/wiki/Printf_format_string
The exponent always contains at least two digits; if the value is zero, the exponent is 00. In Windows, the exponent contains three digits by default, e.g. 1.5e002, but this can be altered by Microsoft-specific _set_output_format function.
所以看起来你可以要求微软的编译器不要添加零。不过,我不知道如何要求 gcc 添加零。
关于linux - 设置 ostream linux/visual studio 的指数字段的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9653489/