프로그래밍 팁

std::string 대소문자 바꾸기

바보 악마 2010. 9. 10. 16:17


원문 : http://neodreamer.tistory.com/267?srchid=BR1http%3A%2F%2Fneodreamer.tistory.com%2F267



#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"


'프로그래밍 팁' 카테고리의 다른 글

typeid memory leak 메모리 릭  (0) 2010.09.17
kgc 2010  (0) 2010.09.16
dir 구현 fileSerch  (0) 2010.09.10
ase Rijndael 암호화 프로그램  (0) 2010.09.10
평면 그리기 plane draw  (0) 2010.09.01