青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 200, comments - 8, trackbacks - 0, articles - 0

c++ cout 格式化輸出(轉(zhuǎn))

Posted on 2012-11-19 14:42 鑫龍 閱讀(547) 評(píng)論(0)  編輯 收藏 引用 所屬分類: c++

cout 格式化輸出


將 cout 的 flag 保存到變量
, 以便修改后的恢復(fù)

ostream::fmtflags old = cout.flag() ; // 無(wú)參將返回當(dāng)前 flag 值 cout.flag(old) ; // 恢復(fù)到原先保存的值


將 bool 值以 literals 輸出

cout <<"numeric : " <<true <<" or " <<false <<endl ; // 1 or 0 cout <<"literals : " <<boolalpha <<true <<" or " <<false <<endl ; // true or false cout <<"literals : " <<boolalpha <<0 <<endl ; // 0 原因: 0 在cout中不等價(jià)于 false

一旦我們使用 boolalpha 將改變 cout 對(duì) bool 值的輸出格式. 此后的 cout 都會(huì)將 bool 輸出為 literals.


將 bool 值以 numeric 輸出

cout <<"numeric : " <<noboolalpha <<true <<" or " <<false <<endl ;// 1 or 0

從此以后, cout 對(duì) bool 值的輸出將恢復(fù) numeric 格式


指定 Integral Values 的 Base

const int ival = 17 ; // 'ival' is constant, so value never change cout <<"oct : " <<oct <<ival <<endl ; // 21 : 8 進(jìn)制 cout <<"dec : " <<dec <<ival <<endl ; // 17 : 10 進(jìn)制 cout <<"hex : " <<hex <<ival <<endl ; // 11 : 16 進(jìn)制 cout <<"hex : " <<hex <<17.01 <<endl ; // 17.01 : 不受影響
如 boolalpha 一樣, oct, dec, hex 也是 persistent. 一旦改變, 將影響后續(xù)的輸出格式.


顯示表明 Integer Values 的 Base

cout <<showbase ; // Show base when printing integral values cout <<"oct : " <<oct <<ival <<endl ; // 21 : 8 進(jìn)制 cout <<"dec : " <<dec <<ival <<endl ; // 017 : 10 進(jìn)制 cout <<"hex : " <<hex <<ival <<endl ; // 0x11 : 16 進(jìn)制 cout <<"hex : " <<hex <<17.01 <<endl ; // 17.01 : 不受影響 cout <<noshowbase ; // Reset state of the stream

若想改變16進(jìn)制字母的大小, 可以結(jié)合 uppercase/nouppercase

cout <<showbase <<uppercase ; cout <<"hex : " <<hex <<15 <<endl ; // 0XF 大寫(xiě)形式 cout <<nouppercase ; cout <<"hex : " <<hex <<15 <<endl ; // 0xf 小寫(xiě)形式

showbase 與 noshowbase 的作用周期也是 persistent


對(duì)于 float/double 型, 有三種格式化控制

一: 輸出精度 precision : by default is 6 pricision
   控制了至多一共會(huì)輸出多少個(gè)數(shù)字.  
   當(dāng)要輸出的數(shù)字多余指定的值時(shí), 將發(fā)生 四舍五入(rounded);  
   當(dāng)要輸出的數(shù)字少于指定的值時(shí), 則實(shí)際輸出的數(shù)字個(gè)數(shù)將少于指定值.
// cout.pricision(4) ; // 等價(jià)于 cout <<setprecision(4) ; cout <<setprecision(4) <<12.345678 <<endl ; // 12.35 rounded! cout <<setprecision(10) <<12.345678 <<endl ; // 12.345678 其實(shí)內(nèi)部發(fā)生了 rounded, 而結(jié)果正好進(jìn)位, 與原值相同 cout <<cout.precision() <<endl ; // 輸出當(dāng)前精度
 二: 表現(xiàn)形式 notation : 'very large and very small values are printed using scientific notation. other values use fixed decimal.'
   notation 控制了輸出的形式 : 科學(xué)計(jì)數(shù)法(scientific) 和 定點(diǎn)小數(shù)(fixed)
float f = 101 / 6.0 ; cout <<fixed <<f <<endl ; // 16.83334 : 小數(shù)點(diǎn)后共6位 cout <<scientific <<f <<endl ; // 1.683333e+001 : 小數(shù)點(diǎn)后共6位
  恢復(fù)到初始狀態(tài)
cout.unsetf(ostream::floatfield) ; // Retrieve to default handling for notation cout <<f <<endl ; // 16.8333 : 所有數(shù)字共6位
 三: 輸出十進(jìn)制浮點(diǎn) 'By default, when the fractional part of a floating-point value is 0, the decimal point is not displayed. The showpoint manipulator forces the decimal point ot be printed.'
cout <<10.0 <<endl ; // 10 cout <<showpoint <<10.0 <<endl ; // 10.0000 cout <<noshowpoint <<endl ; // Revert to default handling of decimal  


輸出填充 
Padding the Output

   setw to specify the minimum space for the next numeric or string value.
cout <<setw(10) <<12.3 <<endl ; // ______12.3 cout <<setw(10) <<12 <<3 <<endl ; // ________123 cout <<setw(3) <<12.345 <<endl ; // If the total output is more than 3, it can be extended
 
   left to left-justify the output.
cout <<left ; // left-justify cout <<setw(5) <<12 <<setw(5) <<34 <<endl ; // 12___34___
 
   right to right-justify the output. Output is right-justified bu default.
cout <<right ; // By default cout <<setw(5) <<12 <<setw(5) <<34 <<endl ; // 12___34___
 
   internal controls placement of the sign on negative value. internal left-justifies the sign and right-justifies the value, padding any intervening space with blanks.(if setfill not set) 
cout <<internal ; // By default cout <<setw(5) <<-12 <<endl ; // 12___34___
 
   setfill lets us specify an alternative character to use when padding the output. By default, the value is a space.
cout <<setfill('*') ; // By default cout <<setw(5) <<12 <<endl ; // 12___34___
 

Header Files

   Manipulators Defined in <iomanip>
setfill(char ch) Fill whitespace with 'ch' setprecision(int n) Set floating-point precision to 'n' setw(int w) Read or write value to 'w' characters setbase(int b) Output integers in base 'b'(only 'b' is 8/10/16 could the function work)
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美成人免费网站| 国产日韩精品入口| 亚洲精品国产系列| 欧美成人综合一区| 亚洲国产精品视频一区| 久久精品女人的天堂av| 亚洲国产日韩综合一区| 国语自产精品视频在线看| 国产精品视区| 国产在线日韩| 在线免费观看日韩欧美| 亚洲高清一区二区三区| 亚洲三级影片| 亚洲一区制服诱惑| 午夜精彩国产免费不卡不顿大片| 亚洲在线中文字幕| 久久9热精品视频| 免费不卡在线视频| 9色国产精品| 欧美一区观看| 欧美经典一区二区| 国产欧美日韩视频一区二区| 伊人成人在线视频| 亚洲午夜未删减在线观看| 久久精品综合网| 另类欧美日韩国产在线| 亚洲精品老司机| 欧美一级专区免费大片| 欧美精品www| 红桃av永久久久| 在线亚洲观看| 久久中文在线| 中文精品视频一区二区在线观看| 性欧美xxxx视频在线观看| 久久蜜臀精品av| 国产精品男人爽免费视频1| 亚洲精品欧美日韩| 欧美一区二区三区四区在线观看地址 | 亚洲精品1区| 亚洲综合色在线| 欧美激情亚洲精品| 欧美一区二区三区在线播放| 能在线观看的日韩av| 国产精品视频网| 亚洲无亚洲人成网站77777| 蜜桃av一区二区三区| 亚洲视频在线视频| 欧美日韩国产综合视频在线观看| 激情视频一区| 久久久久久日产精品| 亚洲一区精彩视频| 亚洲日本欧美在线| 性视频1819p久久| 亚洲另类在线一区| 欧美成人高清视频| 在线观看三级视频欧美| 久久精品国产91精品亚洲| 9色porny自拍视频一区二区| 欧美成人午夜剧场免费观看| 亚洲福利在线看| 久久精品av麻豆的观看方式| 在线成人小视频| 久久婷婷国产综合精品青草| 午夜精品福利视频| 国产精品中文在线| 亚洲欧美色婷婷| 一区二区三区福利| 欧美日韩一区不卡| 亚洲视频1区| 亚洲少妇一区| 欧美性猛交xxxx免费看久久久| 一区二区冒白浆视频| 亚洲精选在线观看| 国产精品初高中精品久久| 亚洲欧美成人精品| 一本色道久久88亚洲综合88| 欧美韩日视频| 日韩一二在线观看| 欧美一区二区三区视频免费| 一区二区三区产品免费精品久久75| 亚洲人成人一区二区在线观看| 欧美91精品| 新片速递亚洲合集欧美合集| 亚洲国产视频直播| 欧美裸体一区二区三区| 欧美a级在线| 欧美肥婆在线| 久久九九国产精品怡红院| 国产精品豆花视频| 欧美精品一区二| 在线亚洲一区二区| 亚洲欧美成人网| 亚洲欧美日韩一区二区三区在线观看 | 国产婷婷色一区二区三区| 午夜精品久久99蜜桃的功能介绍| 亚洲香蕉网站| 激情欧美一区二区| 亚洲第一福利社区| 欧美色中文字幕| 久久精品国产99精品国产亚洲性色 | 有码中文亚洲精品| 亚洲精品久久久蜜桃| 国产精品v日韩精品| 久久久精品动漫| 欧美精品v日韩精品v韩国精品v| 亚洲综合999| 久久九九精品99国产精品| 一区二区三区四区国产| 久久精品欧美| 亚洲欧美三级在线| 欧美日本精品| 免费观看成人www动漫视频| 欧美三级特黄| 乱中年女人伦av一区二区| 国产精品美女999| 亚洲高清精品中出| 国语自产精品视频在线看一大j8 | 国产精品99免费看| 欧美电影在线免费观看网站| 国产精品五区| 一本高清dvd不卡在线观看| 亚洲国产精品悠悠久久琪琪| 午夜精品福利一区二区蜜股av| 99ri日韩精品视频| 久久人体大胆视频| 久久本道综合色狠狠五月| 欧美视频不卡中文| 亚洲精品一区二| 91久久精品国产91久久| 欧美在线免费观看视频| 亚洲综合久久久久| 欧美日韩在线第一页| 亚洲经典自拍| 亚洲一区二区视频| 久久久久亚洲综合| 久久精品人人做人人爽| 国产精品久久毛片a| av成人动漫| 亚洲一区二区三区精品动漫| 欧美国产日韩精品| 亚洲国产精品成人综合色在线婷婷| 国外成人在线视频| 久久久久久久久岛国免费| 久久久精品tv| 国产综合亚洲精品一区二| 午夜激情一区| 老司机精品久久| 久久天天躁狠狠躁夜夜爽蜜月| 久久成人免费电影| 国产在线乱码一区二区三区| 久久国产66| 鲁鲁狠狠狠7777一区二区| 在线日本高清免费不卡| 美女久久一区| 亚洲精品视频免费在线观看| 一本色道综合亚洲| 国产精品毛片大码女人| 欧美一区在线直播| 亚洲欧美日韩精品久久亚洲区| 性亚洲最疯狂xxxx高清| 国产免费观看久久黄| 久久精品视频在线播放| 欧美国产日韩一二三区| 亚洲精品欧美在线| 欧美视频日韩视频| 欧美一区二区三区喷汁尤物| 蜜桃av一区二区| 日韩一区二区久久| 国产精品午夜在线| 久久久久久亚洲综合影院红桃| 欧美高清影院| 亚洲网站啪啪| 狠狠久久五月精品中文字幕| 免费成人黄色片| 亚洲无线观看| 欧美国内亚洲| 国产精品日韩精品欧美精品| 欧美在线观看一区二区| 亚洲国产高清自拍| 欧美在线日韩| 亚洲精品久久在线| 国产精品久久久一区二区| 久久久精品国产免大香伊| 亚洲国产一区二区三区青草影视| 亚洲综合好骚| 日韩一级精品| 在线观看欧美激情| 国内精品久久久久久 | 欧美激情中文字幕一区二区| 亚洲欧美另类中文字幕| 亚洲国产欧美日韩精品| 欧美在线短视频| 在线日韩欧美视频| 国产精品每日更新| 欧美电影在线| 久久久国产精品一区| 一本久久综合亚洲鲁鲁五月天| 蜜桃av久久久亚洲精品| 亚洲欧美视频在线| 亚洲午夜av|