C++中的流操纵器的scientific()方法用于为指定的str流设置floatfield格式标志。此标志将浮点数设置为科学。这意味着浮点值将以科学计数法表示。
用法:
ios_base& scientific (ios_base& str)
参数:此方法接受str作为参数,这是格式标志受影响的流。
返回值:此方法返回设置了内部格式标志的流str。
范例1:
// C++ code to demonstrate
// the working of scientific() function
#include <iostream>
using namespace std;
int main()
{
// Initializing the float values
double x = 1.23;
cout.precision(5);
cout << "without scientific flag:"
<< x << endl;
// Using scientific()
cout << "with scientific flag:"
<< scientific << x << endl;
return 0;
}
输出:
without scientific flag:1.23 with scientific flag:1.23000e+00
范例2:
// C++ code to demonstrate
// the working of scientific() function
#include <iostream>
using namespace std;
int main()
{
// Initializing the float values
double x = 1.0;
cout.precision(5);
cout << "without scientific flag:"
<< x << endl;
// Using scientific()
cout << "with scientific flag:"
<< scientific << x << endl;
return 0;
}
输出:
without scientific flag:1 with scientific flag:1.00000e+00
范例3:
// C++ code to demonstrate
// the working of scientific() function
#include <iostream>
using namespace std;
int main()
{
// Initializing the float values
double x = 1.23e9;
cout.precision(5);
cout << "without scientific flag:"
<< x << endl;
// Using scientific()
cout << "with scientific flag:"
<< scientific << x << endl;
return 0;
}
输出:
without scientific flag:1.23e+09 with scientific flag:1.23000e+09
参考: http://www.cplusplus.com/reference/ios/scientific/
相关用法
- C++ ios manipulators dec()用法及代码示例
- C++ ios manipulators hex()用法及代码示例
- C++ ios manipulators oct()用法及代码示例
- C++ ios manipulators right()用法及代码示例
- C++ ios manipulators noshowpoint()用法及代码示例
- C++ ios manipulators showpos()用法及代码示例
- C++ ios manipulators noshowbase()用法及代码示例
- C++ ios manipulators noshowpos()用法及代码示例
- C++ ios manipulators showbase()用法及代码示例
- C++ ios manipulators boolalpha()用法及代码示例
- C++ ios manipulators noboolapha()用法及代码示例
- C++ ios manipulators showpoint()用法及代码示例
- C++ ios manipulators noskipws()用法及代码示例
- C++ ios manipulators unitbuf()用法及代码示例
- C++ ios manipulators fixed()用法及代码示例
注:本文由纯净天空筛选整理自guptayashgupta53大神的英文原创作品 ios manipulators scientific() function in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。