boost
부스트 문자열 알고리즘 라이브러리
수색…
비고
boost :: split ()
#include <iostream>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
// String to split
string str = "You're supposed to see this!|NOT THIS!!!!!!";
// Line container
vector<string> lines;
// Splits string
boost::split(lines, str, boost::is_any_of("|"), boost::token_compress_on);
// Outputs 1 half of the split string
cout << lines.at(0).c_str() << endl;
// Waits for input before program exits
cin.get();
return 0;
}
psuedocode에 있는 프로그램은 다음과 같습니다.
문자열 str을 선언 하고 이것을 "당신은 이것을 보게된다!"라고 설정 하십시오! | NOT NOT this !!!!!! " .
문자열 유형의 벡터 선 을 선언하십시오 .
regex "|"인 경우 문자열 str 을 벡터 라인 으로 분할 합니다. 발견된다.
행의 인덱스 0에있는 객체를 인쇄 합니다.
입력을 가져옵니다.
Algrorithms 바꾸기
boost :: replace_all () :
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
// String to replace characters in
string str = "Darn you, Darn you to the 5th power!!!";
// Replace "Darn" with "*CENSORED*"
boost::replace_all(str, "Darn", "*CENSORED*");
// Print str
cout << str.c_str() << endl;
// Waits for program to exit
cin.get();
return 0;
}
boost :: replace_first () :
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
// String to replace characters in
string str = "Darn you, Darn you to the 5th power!!!";
// Replace the first instance of "Darn" with "*CENSORED*"
boost::replace_first(str, "Darn", "*CENSORED*");
// Print str
cout << str.c_str() << endl;
// Waits for program to exit
cin.get();
return 0;
}
boost_replace_last () :
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
// String to replace characters in
string str = "Darn you, Darn you to the 5th power!!!";
// Replace the last instance of "Darn" with "*CENSORED*"
boost::replace_last(str, "Darn", "*CENSORED*");
// Print str
cout << str.c_str() << endl;
// Waits for program to exit
cin.get();
return 0;
}
사례 변환 방법
to_upper () :
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
// String to convert characters to uppercase
string str = "ThIS iS SUpPoSEd tO Be UpPeR CAsE.";
// Convert characters in str to upper case
boost::to_upper(str);
// Print str
cout << str.c_str() << endl;
// Waits for program to exit
cin.get();
return 0;
}
to_lower () :
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
// String to convert characters to lowercase
string str = "ThIS iS SUpPoSEd tO Be LoWer CAsE.";
// Convert characters in str to lower case
boost::to_lower(str);
// Print str
cout << str.c_str() << endl;
// Waits for program to exit
cin.get();
return 0;
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow