(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); setw() 함수 :: 깜냥깜냥

setw()

1.setw()는 C++ 함수이다..
2.setw() #include<iomanip>에 공표되어있는 함수이다.
3.setw()는 데이터가 출력 된 화면을 지정한 수만큼 폭을 정렬해준다.



ex)
1
2
3
4
5
6
7
8
9
10
#include <iostream>  
#include <iomanip>
 
using namespace std;
 
int main () {
  char a[10]={"hello"};
  cout <<setw(10)<< a <<endl;
  return 0;
}
cs

위와 같이 setw(int num)형식을 써준다. cout.setf(ios::left),cout.setf(ios::right)를 써준다면 좌측,우측 정렬을 할 수 있다.

ex)
1
2
3
4
//////////////생략///////////
  cout.setf(ios::left);
  cout <<setw(10)<< a <<endl;
//////////////생략///////////
cs
좌측 정렬

1
2
3
4
//////////////생략///////////
  cout.setf(ios::right);
  cout <<setw(10)<< a <<endl;
//////////////생략///////////
cs

우측 정렬 

'code > C++' 카테고리의 다른 글

[C++] Stack&Queue (예외처리, 소멸자, 템플릿 포함)  (0) 2017.04.20
[C++] 템플릿  (0) 2017.04.20
[c++] 연산자 함수  (0) 2017.04.20
[c++] private 상속  (0) 2017.04.20
[C++] protected 상속  (0) 2017.04.20

+ Recent posts