#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//숫자 출력 위주로
//flag설정하는 것 부터
cout.setf(ios::showpos);
cout << 108 << endl;
cout.unsetf(ios::showpos);
cout << 109 << endl;
return 0;
}
cout.setf(ios::showpos)로 flag 설정
cout.unsetf(ios::showpos)로 flag 해제
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//10진수 mode를 끄고 16진수 mode를 켜야함
cout.unsetf(ios::dec);
cout.setf(ios::hex);
cout << 108 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//basefield에서 hex를 실행시켜줌
cout.setf(ios::hex, ios::basefield);
cout << 108 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << hex;
cout << 108 << endl;
return 0;
}
10진수 -> 16진수로 바꾸는 과정
세 코드다 결과는 동일하다.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout.setf(ios::uppercase); // 16진수 대분자로 출력
cout << hex;//uppercase 추가로 출력하게도
cout << 108 << endl;
cout << 199 << endl;
cout << dec;
cout << 108 << endl;
cout << 199 << endl;
return 0;
}
16진수와 10진수 왔다갔다 하는 과정
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << boolalpha;
cout << true << " " << false << endl;
return 0;
}
boolalpha가 없으면 1, 0 이렇게 출력이 되고
있으면 true, false 이렇게 출력이 된다.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << defaultfloat; //기본으로 설정되어있는 것
cout << setprecision(3) << 123.456 << endl;
cout << setprecision(4) << 123.456 << endl;
cout << setprecision(5) << 123.456 << endl;
cout << setprecision(6) << 123.456 << endl;
cout << setprecision(7) << 123.456 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << fixed; //소수점 뒤에 자리 나타냄₩
cout << setprecision(3) << 123.456 << endl;
cout << setprecision(4) << 123.456 << endl;
cout << setprecision(5) << 123.456 << endl;
cout << setprecision(6) << 123.456 << endl;
cout << setprecision(7) << 123.456 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << scientific << uppercase; //소수점 뒤에 자리 나타냄₩
cout << setprecision(3) << 123.456 << endl;
cout << setprecision(4) << 123.456 << endl;
cout << setprecision(5) << 123.456 << endl;
cout << setprecision(6) << 123.456 << endl;
cout << setprecision(7) << 123.456 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << showpoint;
cout << setprecision(3) << 123.456 << endl;
cout << setprecision(4) << 123.456 << endl;
cout << setprecision(5) << 123.456 << endl;
cout << setprecision(6) << 123.456 << endl;
cout << setprecision(7) << 123.456 << endl;
return 0;
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << -12345 << endl;
//cout.fill('*');
cout << setw(10) << -12345 << endl;
cout << setw(10) << left << -12345 << endl;
cout << setw(10) << right << -12345 << endl;
cout << setw(10) << internal << -12345 << endl;
return 0;
}