C, C++

조정자(Manipulator)

Jcon 2022. 8. 17. 21:39
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{	//															출력
	cout << showpos		<< 123	<<endl;						//	+123
	cout << noshowpos	<< 123	<< endl;					//	123
	
	cout << dec			<< 15	<< endl;					//	15
	cout << hex			<< 15	<< endl;					//	f
	cout << oct			<< 8	<< endl;					//	10
	
	cout << uppercase	<< hex	<< 15	<< endl;			//	F
	cout << nouppercase << hex	<< 15	<< endl;			//	f
	
	cout << showbase	<< hex	<< 15	<< endl;			//	0xf
	cout << noshowbase	<< hex	<< 15	<< endl;			//	f
	
	cout << showpoint	<< 10.f << " " << 10.12f << endl;	//	10.0000 10.1200
	cout << noshowpoint << 10.f << " " << 10.12f << endl;	//	10 10.12
	
	cout << fixed << 10.01f << endl;						//	10.010000
	cout << scientific << 10.01f << endl;					//	1.001000e+01

    cout.setf(ios_base::hex);								//메서드 형태도 있음
	cout.unsetf(ios_base::hex);

	cout.width(5); 
	cout.fill('*'); 
	cout << 123 << endl;									//	**123

	cout.fill(' ');

//#include <iomanip>
	cout << setw(5) << 123 << endl;							//	 -123
	cout << setw(5) << left << -123 << endl;				//	-123
	cout << setw(5) << internal << -123 << endl;			//	- 123
	cout << setfill('*') << setw(5) << 123 << endl;			//	**123
	cout << setprecision(7) << 123.45678 << endl;			//	123.4568
															//		   └> 반올림
}