C++筆記——浮點數精度、進制數輸出

//UE中配置VS2010 cl編譯器
#include <iostream>
using namespace std;
#include <iomanip>
#include <bitset>

void func(int a){
	cout << "void func(int a)" << endl;
}
void func(int *p){
	cout << "void func(int *p)" << endl;
}

int main()
{
	//bool輸出
	bool flag = true;
	cout << "flag:" << flag << endl;
	cout << "flag:" << boolalpha << flag << endl;
	
	//空指針nullptr
	func(0);//func(NULL);
	func(nullptr);

	//輸出浮點數的精度
	float f = 1.235;
	cout<<"default :"<<f<<endl;
	cout<<"format:"<<setprecision(2)<<setiosflags(ios::fixed)<<f<<endl;
	cout<<"format:"<<setprecision(4)<<setiosflags(ios::fixed)<<f<<endl;
	
	//進制
	int i = 255;
	cout<<i<<endl;
	cout<<"dec:"<<dec<<i<<endl; //十進制
	cout<<"hex:"<<hex<<i<<endl; //十六進制
	cout<<"oct:"<<oct<<i<<endl; // 八進制
	//cout<<setbase(16)<<i<<endl; //設置進制
	cout << bitset<8>(i) << endl;//二進制
	
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章