使用cout进行双重表示

double representation using cout

本文关键字:表示 cout 使用      更新时间:2023-10-16

我有一个简单的程序:

#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
double i=0.000006;
printf("%lfn",i);
cout <<i<<endl;
return 0;
}

,其输出为:

pearl.236> ./a.out
0.000006
6e-06
pearl.237> 

如何使用cout实现0.000006 ?

我遇到的实际问题是我将这个双精度重定向到字符串流,然后我将它打印在屏幕上。我想知道如何在字符串流中存储实际的双精度表示

在操纵符的帮助下实现流格式化。指定标准符号和科学符号的操纵符为fixedscientific

cout << fixed <<i<<endl;

尝试使用std::fixed

std::cout << std::fixed << i << "n";