can't print more decimal of pi [duplicate]

喜你入骨 提交于 2019-12-02 03:53:57

Like so:

#include <iomanip>
#include <iostream>

std::cout << std::setw(15) << pi_18 << std::endl;

The width modifier only affects the next formatting operation, so if you want to format multiple numbers, you have to repeat it before every one. Check out the full documentation of format specifiers.

You could use the precision method:

cout.precision(15);

This allows you to define the precision only once. You don't have to repeat it like with std::setw()

For more information see: http://en.cppreference.com/w/cpp/io/ios_base/precision

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!