C++/0x02-boost

boost replace

SpeeDr00t 2016. 8. 1. 13:42
반응형

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$
반응형