#include <iostream> #include <iomanip> using namespace std;
int main() { int a=1234; cout << "a= " << a << endl; //a의 값 출력 cout << "a= " << setw(5) << a << endl; //출력폭이 5이므로 빈칸까지 출력 cout << "a= " << hex << setw(5) <<a << endl;//헥사값으로 빈칸까지 출력. cout << "a= " << dec << setw(5) <<a << endl;//10진수로 빈칸까지 출겨하여 5자리 맞춤.
double b=45.8769; cout << "b= " << b << endl;//45.8769출력. cout << "b= " << fixed << b << endl;//실수형을 본래 형태로 출력.
cout << "b= " << setprecision(0) << b << endl; //소수점 이하 자리수. 0으로 설정하면 자연수만 나온다. 단, 반올림한다.
double c = 123;
cout << "c= " << c << endl;//123출력 cout << "c= " << setprecision(0) << c << endl;//자연수 123출력 cout << "c= " << showpoint << c << endl; //소수점 출력. 여기서는 소수점이 없기 때문에 .만 출력 //반드시 출력. cout << 987.0 << endl;
return 0; }
|