setprecision()的固定功能很粘

时间:2017-12-12 23:19:43

标签: c++

#include <iostream>
#include <iomanip>
int main() {
    float a = 456.123456789;
    std::cout << a << "\n"; //State 1
    std::cout << "fixed " << fixed << a << "\n"; //State 2
    std::cout << a << "\n"; //State 3
}

输出:

456.123 //State 1
fixed 456.123444 //State 2
456.123444 //State 3

我想要做的是切换回状态1,那我该怎么做呢?我尝试了一些基于http://www.cplusplus.com/reference/iomanip/setprecision/的事情,但都失败了。

0 个答案:

没有答案