반응형
tolower
,toupper
a~z, A~Z 의 범위를 변환 시킨다
http://neodreamer.tistory.com/267
std::transform 함와 cctype 헤더의 tolower() 와 toupper() 함수를 이용하면 쉽게 해결이 되었다.
transform 함수는 이외에도 응용할 부분이 많아보인다. container 의 각 원소에 특정을 변형을 주어
바꾸거나 다는 container에 넣을 수도 있다. transform 함수에 대해서는 좀더 공부를 해서 나중에 포스팅을 한번 해야겠다.
#include <cctype> // for toupper & tolower
#include <string>
#include <algorithm>
using namespace std;
// 대문자로 바꾸기
string s1 = "sample string";
transform( s1.begin(), s1.end(), s1.begin(), toupper );
// 결과 : s1 "SAMPLE STRING"
// 소문자로 바꾸기
string s2 = "HELLO";
transform( s2.begin(), s2.end(), s2.begin(), tolower );
// 결과 : s2 "hello"
// 첫 문자만 대문자로 바꾸기
string s3 = "title";
transform( s3.begin(), s3.begin() + 1, s3.begin(), toupper );
// 결과 : s3 "Title"
반응형
'STLTemplate > STL & EffectiveSTL' 카테고리의 다른 글
3. STL 연관 컨테이너 - 19 (0) | 2012.11.01 |
---|---|
문자열과 integer,float 사이의 변환 (atoi, stringstream) (0) | 2012.11.01 |
STL bitset 진수 변환 (0) | 2012.11.01 |
STL 무한대, numeric_limits::infinity (0) | 2012.11.01 |
lower_bound,upper_bound 예제소스 (0) | 2012.11.01 |