在C++中用SETFLID()打印特定格式的十进制数
我正在尝试按以下格式打印十进制数字:+3.01 案例:在这种情况下有一个小数,比如说3.01。我必须打印它的符号+/-,前面有y编号,总宽度固定。在这种情况下,假设x=10 我试过这样做: 预期产出:在C++中用SETFLID()打印特定格式的十进制数,c++,C++,我正在尝试按以下格式打印十进制数字:+3.01 案例:在这种情况下有一个小数,比如说3.01。我必须打印它的符号+/-,前面有y编号,总宽度固定。在这种情况下,假设x=10 我试过这样做: 预期产出: 你的代码给了我正确的结果。我正在使用Linux机器 如果是操作系统相关的问题,请尝试以下代码: #include <iostream> #include <iomanip> using namespace std; int main() { double no
你的代码给了我正确的结果。我正在使用Linux机器 如果是操作系统相关的问题,请尝试以下代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double no = 3.01;
cout << setfill('#') << std::right<< setw(10) ;
cout << setiosflags(ios::showpos);
cout << fixed << setprecision(2) << no << endl;
}
可能重复的
+#####3.01
#####+3.01
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double no = 3.01;
cout << setfill('#') << std::right<< setw(10) ;
cout << setiosflags(ios::showpos);
cout << fixed << setprecision(2) << no << endl;
}