欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解析C++ 浮點(diǎn)數(shù)的格式化輸出

 更新時(shí)間:2013年05月30日 17:20:21   作者:  
本篇文章是對(duì)C++中浮點(diǎn)數(shù)的格式化輸出進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
C++格式化輸出浮點(diǎn)數(shù)
復(fù)制代碼 代碼如下:

#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
using std::scientific;
int main()
{
   double x = 0.001234567;
   double y = 1.946e9;
   cout << "Displayed in default format:" << endl << x << '/t' << y << endl;
   cout << "/nDisplayed in scientific format:" << endl << scientific << x << '/t' << y << endl;
   cout << "/nDisplayed in fixed format:" << endl << fixed << x << '/t' << y << endl;
   return 0;
}

Displayed in default format:
0.00123457      1.946e+009
Displayed in scientific format:
1.234567e-003   1.946000e+009
Displayed in fixed format:
0.001235        1946000000.000000
復(fù)制代碼 代碼如下:

#include <iostream.h>
main(void)
{
  float a=100100.0, b=0.08;
  cout.setf(ios::right|ios::scientific|ios::showpoint);
  cout.width(20);  
  cout <<(-a*b);

  return 0;
}

-8.008000e+003
復(fù)制代碼 代碼如下:

#include <iostream>
#include <iomanip>
#include <limits>
using std::cout;
using std::endl;
using std::setprecision;
using std::numeric_limits;
int main() {
  const double pi = 3.14;
  cout << endl;
  for(double radius = .2 ; radius <= 3.0 ; radius += .2)
    cout << "radius = "
    << setprecision(numeric_limits<double>::digits10 + 1)
    << std::scientific << radius<< "  area = "
         << std::setw(10) << setprecision(6)<< std::fixed << pi * radius * radi
us << endl;
  return 0;
}

radius = 2.0000000000000001e-001  area =   0.125600
radius = 4.0000000000000002e-001  area =   0.502400
radius = 6.0000000000000009e-001  area =   1.130400
radius = 8.0000000000000004e-001  area =   2.009600
radius = 1.0000000000000000e+000  area =   3.140000
radius = 1.2000000000000000e+000  area =   4.521600
radius = 1.3999999999999999e+000  area =   6.154400
radius = 1.5999999999999999e+000  area =   8.038400
radius = 1.7999999999999998e+000  area =  10.173600
radius = 1.9999999999999998e+000  area =  12.560000
radius = 2.1999999999999997e+000  area =  15.197600
radius = 2.3999999999999999e+000  area =  18.086400
radius = 2.6000000000000001e+000  area =  21.226400
radius = 2.8000000000000003e+000  area =  24.617600
復(fù)制代碼 代碼如下:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main( ) {
   ios_base::fmtflags flags = cout.flags( );
   double pi = 3.14285714;
   cout << "pi = " << setprecision(5) << pi << '/n';
   cout.flags(flags);
}

pi = 3.1429
復(fù)制代碼 代碼如下:

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
   double root2 = sqrt( 2.0 );
   int places;
   cout << setiosflags( ios::fixed)
        << "Square root of 2 with precisions 0-9./n"
        << "Precision set by the "
        << "precision member function:" << endl;
   for ( places = 0; places <= 9; places++ ) {
      cout.precision( places );
      cout << root2 << '/n';
   }
   cout << "/nPrecision set by the "
        << "setprecision manipulator:/n";
   for ( places = 0; places <= 9; places++ )
      cout << setprecision( places ) << root2 << '/n';
   return 0;
}

相關(guān)文章

  • QT樹(shù)的具體項(xiàng)目實(shí)現(xiàn)

    QT樹(shù)的具體項(xiàng)目實(shí)現(xiàn)

    本文主要介紹了QT樹(shù)的具體項(xiàng)目實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • C++字符串類的封裝你真的了解嗎

    C++字符串類的封裝你真的了解嗎

    這篇文章主要為大家詳細(xì)介紹了C++字符串類的封裝,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • 基于Qt實(shí)現(xiàn)C/C++調(diào)用Matlab函數(shù)全過(guò)程

    基于Qt實(shí)現(xiàn)C/C++調(diào)用Matlab函數(shù)全過(guò)程

    這篇文章給大家詳細(xì)介紹了基于Qt平臺(tái)實(shí)現(xiàn)C/C++調(diào)用Matlab函數(shù)全流程,文中通過(guò)圖文和代碼示例給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-01-01
  • C++實(shí)現(xiàn)掃雷程序開(kāi)發(fā)

    C++實(shí)現(xiàn)掃雷程序開(kāi)發(fā)

    這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)掃雷程序開(kāi)發(fā),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Qt GUI圖形圖像開(kāi)發(fā)之QT表格控件QTableView詳細(xì)使用方法與實(shí)例

    Qt GUI圖形圖像開(kāi)發(fā)之QT表格控件QTableView詳細(xì)使用方法與實(shí)例

    這篇文章主要介紹了Qt GUI圖形圖像開(kāi)發(fā)之QT表格控件QTableView詳細(xì)使用方法與實(shí)例,需要的朋友可以參考下
    2020-03-03
  • C++-操作符重載、并實(shí)現(xiàn)復(fù)數(shù)類詳解

    C++-操作符重載、并實(shí)現(xiàn)復(fù)數(shù)類詳解

    這篇文章主要介紹了C++-操作符重載、并實(shí)現(xiàn)復(fù)數(shù)類,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Qt模仿IOS滑動(dòng)按鈕效果

    Qt模仿IOS滑動(dòng)按鈕效果

    這篇文章主要為大家詳細(xì)介紹了Qt模仿IOS滑動(dòng)按鈕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • C++回溯算法廣度優(yōu)先搜索舉例分析

    C++回溯算法廣度優(yōu)先搜索舉例分析

    回溯在迷宮搜索中使用很常見(jiàn),就是這條路走不通,然后返回前一個(gè)路口,繼續(xù)下一條路?;厮菟惴ㄕf(shuō)白了就是窮舉法,下面讓我們一起來(lái)看看吧
    2022-03-03
  • C++入門基礎(chǔ)之命名空間、輸入輸出和缺省參數(shù)

    C++入門基礎(chǔ)之命名空間、輸入輸出和缺省參數(shù)

    C++入門基礎(chǔ)篇的內(nèi)容為C++的基本特性,只有在掌握C++的基本特性后,是進(jìn)入后面類和對(duì)象學(xué)習(xí)的基礎(chǔ),下面這篇文章主要給大家介紹了關(guān)于C++入門基礎(chǔ)之命名空間、輸入輸出和缺省參數(shù)的相關(guān)資料,需要的朋友可以參考下
    2023-01-01
  • Qt實(shí)現(xiàn)兩個(gè)獨(dú)立窗口的信號(hào)通信

    Qt實(shí)現(xiàn)兩個(gè)獨(dú)立窗口的信號(hào)通信

    這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)兩個(gè)獨(dú)立窗口的信號(hào)通信,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01

最新評(píng)論