歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> C++其他幾個常見操作程序

C++其他幾個常見操作程序

日期:2017/3/1 9:43:22   编辑:Linux編程

在上文介紹了setw()操作程序(http://www.linuxidc.com/Linux/2014-06/102914.htm),下面介紹其他幾個,setprecision()指定用多少位數來表示浮點數,fixed表示以固定點表示法輸出浮點數值,即不帶指數。scientific以科學表示法輸出浮點數值,即尾數加指數的方式。而默認的是根據要顯示的數值,選擇fixed或者scientific表示法。

示例如下:

#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::scientific;
int main(void){
float v1=0.1f;
float v2=2.1f;
v1-=0.09f;
v2-=2.09f;
cout<<setprecision(14)<<fixed;
cout<<v1-v2<<endl;
cout<<setprecision(5)<<scientific;
cout<<v1-v2<<endl;
return 0;

}

C++ Primer Plus 第6版 中文版 清晰有書簽PDF+源代碼 http://www.linuxidc.com/Linux/2014-05/101227.htm

讀C++ Primer 之構造函數陷阱 http://www.linuxidc.com/Linux/2011-08/40176.htm

讀C++ Primer 之智能指針 http://www.linuxidc.com/Linux/2011-08/40177.htm

讀C++ Primer 之句柄類 http://www.linuxidc.com/Linux/2011-08/40175.htm

C++11 獲取系統時間庫函數 time since epoch http://www.linuxidc.com/Linux/2014-03/97446.htm

C++11中正則表達式測試 http://www.linuxidc.com/Linux/2012-08/69086.htm

Copyright © Linux教程網 All Rights Reserved