티스토리 뷰

*입출력 형식

1
2
3
4
5
6
cout.setf(ios_base::boolalpha);
cout << true << endl;
cout.setf(ios_base::hex, ios_base::basefield);//16진수로 출력
cout << 123 << endl;
cout.setf(ios_base::showpoint | ios_base::showpos);//showpoint : 실수형이면 소숫점표시 showpos : 양수형이면 + 표시
cout << 123.<< endl;
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
인자가 2개
cout << 12.34 << endl;
 
ios_base::fmtflags prev;
prev = cout.setf(ios_base::scientific, ios_base::floatfield);
cout << 12.34 << endl;
 
cout.setf(prev, ios_base::floatfield);
cout << 12.34 << endl;
 
인자가 1개
cout.setf(ios_base::showpos);
cout.unsetf(ios_base::showpos);
cs


1
2
3
4
5
6
7
8
cout.fill('0');//문자만 채운다.
cout.width(10);
cout << 123 << endl;
 
cout.setf(ios_base::fixed);//cout.fixed;
cout.precision(2);//반올림
cout << 3.467 << endl;
 
cs


*조종자

1
#include <iomanip>
cs

를 추가해야합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
cout << boolalpha << true << endl;
cout << showbase << dec << 123 << endl;//10진수
cout << showbase << oct << 123 << endl;//8진수
cout << showbase << hex << 123 << endl;//16진수
cout << showpoint << 123.<< endl;
cout << uppercase << hex<< 123 << endl;//16진수의 대문자 표현
cout << fixed << setprecision(2<< 123.456 << endl;
cout << scientific << 123.456 << endl;
cout << setw(10<< internal << hex << 123 << endl;//0X      7B
cout << setw(10<< internal << dec <<-123 << endl;//-      123
cout << setw(10<< left << -123 << endl;
cout << setw(10<< right << -123 << endl;//      -123
 
cs


1
2
3
cout << setbase(10<< 123 << endl;
cout << setbase(8<< 123 << endl;
cout << setbase(16<< 123 << endl;


cs

1
2
3
4
5
6
7
8
9
10
printf("%d\n"123); //10진수
printf("%o\n"123); //8진수
printf("%X\n"123); //16진수 대문자 출력
printf("%f\n"123.456); //123.456000
printf("%.2f\n"123.456); //123.46
printf("%e\n"123.456); //1.234560e+02
printf("%10d\n"123);
printf("%010d\n"123);
printf("%-10d\n"-123);
printf("%10d\n"-123);
cs

*스트림의 상태

1
2
3
4
cin.good();
cin.eof();
cin.fail(); // 실패 시 return true
cin.bad(); // 잘못된 파일 return true
cs


*파일 입출력

1
2
3
4
5
6
7
8
9
10
11
12
ofstream file1("test.txt");
ofstream file2;
file2.open("test.txt");
ofstream file3("test.txt", ios_base::out | ios_base::trunc);
/*
out : 쓰기
in : 읽기
trunc : 지우고 새로운 파일
app : 파일 끝에 내용 추가
ate : 파일 끝으로 이동
*/
if (file1.is_open()) {};
cs


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
글 보관함