Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我正在尝试找出是否有办法为 ofstreams 设置默认精度。为了澄清,我可以毫无问题地设置我定义的 ofstream 的精度。我只是找不到一种方法,所以当我创建一个 ofstream 时,它默认具有这种精度。提前致谢。
也许通过ofstream在其构造函数中派生您自己的版本来设置精度:
ofstream
#include <fstream> struct my_ofstream : std::ofstream { explicit my_ofstream(std::streamsize prec = 5) { this->precision(prec); } }; int main() { my_ofstream f1; // default precision 5 my_ofstream f2(10); }