最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2013年05月30日 17:20:21   作者:  
本篇文章是對C++中浮點數(shù)的格式化輸出進行了詳細的分析介紹,需要的朋友參考下
C++格式化輸出浮點數(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)文章

  • C語言版二值圖像統(tǒng)計連通區(qū)域

    C語言版二值圖像統(tǒng)計連通區(qū)域

    這篇文章主要為大家詳細介紹了C語言版二值圖像統(tǒng)計連通區(qū)域的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • C++中日期類的常見題目合集分享

    C++中日期類的常見題目合集分享

    這篇文章主要為大家詳細介紹了一些C++中日期類的常見題目,文中的示例代碼講解詳細,對我們掌握C++有一定的幫助,感興趣的小伙伴可以了解一下
    2023-06-06
  • C++實現(xiàn)翻轉(zhuǎn)單詞順序

    C++實現(xiàn)翻轉(zhuǎn)單詞順序

    這篇文章給大家匯總介紹了C++實現(xiàn)翻轉(zhuǎn)單詞順序的三種方法,都非常的簡單,需要的朋友可以參考下
    2016-07-07
  • c++ 構(gòu)造函數(shù)的初始化列表

    c++ 構(gòu)造函數(shù)的初始化列表

    構(gòu)造函數(shù)的初始化列表僅僅指定用于初始化成員的值,并不指定這些初始化執(zhí)行的次序。成員初始化的次序就是定義成員的次序,第一個成員首先被初始化,然后是第二個,依次類推
    2013-07-07
  • C++深入探究list的模擬實現(xiàn)

    C++深入探究list的模擬實現(xiàn)

    list相較于vector來說會顯得復(fù)雜,它的好處是在任意位置插入,刪除都是一個O(1)的時間復(fù)雜度,本文主要介紹了C++中List的模擬實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • 關(guān)于C++虛繼承的內(nèi)存模型問題

    關(guān)于C++虛繼承的內(nèi)存模型問題

    C++虛繼承的內(nèi)存模型是一個老生常談的話題,實現(xiàn)方法主要依賴于編譯器,本文從多個角度通過代碼詳解C++中虛繼承的內(nèi)存模型知識,感興趣的朋友跟隨小編一起看看吧
    2021-07-07
  • C語言文件操作之fread函數(shù)詳解

    C語言文件操作之fread函數(shù)詳解

    fread()函數(shù)用來從指定文件中讀取塊數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于C語言文件操作之fread函數(shù)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-06-06
  • c++將引用或者是指針作為函數(shù)參數(shù)實現(xiàn)實參的運算

    c++將引用或者是指針作為函數(shù)參數(shù)實現(xiàn)實參的運算

    這篇文章主要介紹了c++將引用或者是指針作為函數(shù)參數(shù)實現(xiàn)實參的運算,需要的朋友可以參考下
    2014-05-05
  • C++ Boost Random隨機函數(shù)詳解

    C++ Boost Random隨機函數(shù)詳解

    Boost是為C++語言標準庫提供擴展的一些C++程序庫的總稱。Boost庫是一個可移植、提供源代碼的C++庫,作為標準庫的后備,是C++標準化進程的開發(fā)引擎之一,是為C++語言標準庫提供擴展的一些C++程序庫的總稱
    2022-11-11
  • 嵌入式項目使用C語言結(jié)構(gòu)體位段特性實現(xiàn)斷言宏校驗數(shù)據(jù)范圍有效性的方法

    嵌入式項目使用C語言結(jié)構(gòu)體位段特性實現(xiàn)斷言宏校驗數(shù)據(jù)范圍有效性的方法

    今天小編就為大家分享一篇關(guān)于嵌入式項目使用C語言結(jié)構(gòu)體位段特性實現(xiàn)斷言宏校驗數(shù)據(jù)范圍有效性的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12

最新評論

长海县| 潮州市| 江达县| 宁远县| 绥德县| 雷山县| 柳州市| 马山县| 辽阳县| 大足县| 保康县| 台北市| 遵义县| 房山区| 阜城县| 牡丹江市| 朝阳县| 华容县| 富阳市| 财经| 建湖县| 独山县| 镇沅| 三门县| 子洲县| 兴山县| 栖霞市| 东安县| 宜春市| 周口市| 湖州市| 无为县| 乌什县| 兴仁县| 奉新县| 通化市| 铁岭市| 合川市| 垣曲县| 依兰县| 武乡县|