본문 바로가기
C++/0x02-boost

boost trimming

by SpeeDr00t 2016. 8. 1.
반응형

boost trimming

1.소스

#include <boost/algorithm/string.hpp>
#include <iostream>

using namespace std;
using namespace boost;

int main( int argc , char ** argv )
{


    string str1 = "     hello world!     ";
    cout << "str1 = " << str1 << endl;

    string str2 = trim_left_copy(str1);       // str2 == "hello world!     "
    cout << " trim_left_copy( str2 )  = " << str2 << endl;

    string str3 = trim_right_copy(str1);      // str3 == "     hello world!"
    cout << " trim_right_copy( str3 ) = " << str3 << endl;

    trim(str1);                              // str1 == "hello world!"
    cout << " trim(str1) = " << str1 << endl;

    string phone = "00423333444";
    cout << " phone = " << phone << endl;

    // remove leading 0 from the phone number
    trim_left_if( phone , is_any_of("0") );    // phone == "423333444"
    cout << " trim_left_if( phone , is_any_of(\"0\") )  = " << phone << endl;

}

결과

hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ c++ -I /home/hacker/boost_1_61_0 -oboost_trimming  boost_trimming.cpp
hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ ./boost_trimming 
str1 =      hello world!     
 trim_left_copy( str2 )  = hello world!     
 trim_right_copy( str3 ) =      hello world!
 trim(str1) = hello world!
 phone = 00423333444
 trim_left_if( phone , is_any_of("0") )  = 423333444
hacker@ubuntu:~/cpp$ 
반응형

'C++ > 0x02-boost' 카테고리의 다른 글

boost replace  (0) 2016.08.01
boost find  (0) 2016.08.01
boost helloworld  (0) 2016.08.01
boost example2  (0) 2016.08.01
boost example  (0) 2016.08.01