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

boost replace

by SpeeDr00t 2016. 8. 1.
반응형

boost replace

1.소스

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

using namespace std;
using namespace boost;

int main( int argc , char ** argv )
{
    string str1  = "hello black falcon ab";

    cout << "str1 = " << str1 << endl;


    replace_first( str1 , "hello", "goodbye");
    cout << "replace_first( str1 , \"hello\", \"goodbye\") = " << str1 << endl;


    replace_last( str1 , "black", "white");
    cout << "replace_first( str1 , \"black\", \"white\") = " << str1 << endl;

    erase_all( str1, " " );
    cout << "erase_all( str1, \" \" )" << str1 << endl;

    erase_head( str1, 4 );
    cout << "erase_head( str1, 4 ) = " << str1 << endl;



return 0;
}

결과

hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ c++ -I /home/hacker/boost_1_61_0 -o boost_replace1  boost_replace1.cpp
hacker@ubuntu:~/cpp$ 
hacker@ubuntu:~/cpp$ ./boost_replace1 
str1 = hello black falcon ab
replace_first( str1 , "hello", "goodbye") = goodbye black falcon ab
replace_first( str1 , "black", "white") = goodbye white falcon ab
erase_all( str1, " " )goodbyewhitefalconab
erase_head( str1, 4 ) = byewhitefalconab
hacker@ubuntu:~/cpp$
반응형

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

boost iterator_range  (0) 2016.08.01
boost c++ 라이브러리 사용하기 ][ find iterator  (0) 2016.08.01
boost find  (0) 2016.08.01
boost trimming  (0) 2016.08.01
boost helloworld  (0) 2016.08.01