문제 :
0에서 127까지 ASCII 코드와 해당 문자를 다음과 같이 출력하는 프로그램을 작성하라.
화면에 출력가능하지 않는 ASCII 코드는 ‘.‘으로 출력하라.
실행 결과 :

목적 및 힌트 :
cout으로 포맷 출력 응용 연습
문자가 출력 가능한지 알기 위해 bool isprint(int c); 함수를 사용하면 됩니다.
매개 변수 c는 문자 코드 값이고,
코드 :
| 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include |
설명 :
포맷 출력을 하기 위해 조작자 setw() 함수를 사용하였고, 사용하기 위해서는 iomanip 헤더 파일을 include 해주어야 합니다.
입출력 조작자(manipulator)는 std::basic_ostream의 « (출력)연산자나 std::basic_istream의 » (입력)연산자와 함께 사용할 수 있습니다.
또한 왼쪽으로 정렬하여 출력하는 포맷을 지정하기 위해 cout.setf(ios::left); 코드를 사용했고, ios_base::setf() 함수와 조작자에 대한 내용은 아래 링크에서 자세히 볼 수 있습니다.
http://www.cplusplus.com/reference/library/manipulators/
[manipulators - C++ Reference
www.cplusplus.com](http://www.cplusplus.com/reference/library/manipulators/)
http://www.cplusplus.com/reference/ios/ios_base/setf/
[ios_base::setf - C++ Reference
public member function set (1)fmtflags setf (fmtflags fmtfl); mask (2)fmtflags setf (fmtflags fmtfl, fmtflags mask); Set specific format flags The first form (1) sets the stream’s format flags whose bits are set in fmtfl, leaving unchanged
www.cplusplus.com](http://www.cplusplus.com/reference/ios/ios_base/setf/)
공유하기
게시글 관리
코딩은 내일부터 ;
‘💻 개발 & CS > C++ 프로그래밍’ 카테고리의 다른 글
| 명품 C++ programming 실습 문제 11장 9번 (3) | 2020.04.02 |
| 명품 C++ programming 실습 문제 11장 8번 (1) | 2020.04.02 |
| 명품 C++ programming 실습 문제 11장 6번 (1) | 2020.03.27 |
| 명품 C++ programming 실습 문제 11장 5번 (3) | 2020.03.27 |
| 명품 C++ programming 실습 문제 11장 4번 (1) | 2020.03.27 |