このコードを書いて、多くのスペースやタブを含む単語を含む文字列を単語だけを含む文字列ベクトルに分割しました。単語内のスペースを削除するためにブースト文字列を分割する
1 #include<iostream>
2 #include<vector>
3 #include<boost/algorithm/string/split.hpp>
4 #include<boost/algorithm/string.hpp>
5 int main()
6 {
7 using namespace std;
8
9 string str("cONtainS SoMe CApiTaL WORDS");
10
11 vector<string> strVec;
12 using boost::is_any_of;
13
14 boost::algorithm::split(strVec, str, is_any_of("\t "));
15
16 vector<string>::iterator i ;
17
18 for(i = strVec.begin() ; i != strVec.end(); i++)
19 cout<<*i<<endl;
20
21 return 0;
22 }
23
私は出力
cONtainS
SoMe
CApiTaL
WORDS
しかしイムstrVecすなわち
cONtainS
SoMe
CApiTaL
WORDS