再來, 取 token. 就是把資料從字串中分離出來.
請看 boost庫的 Tokenizer.
http://www.boost.org/libs/tokenizer/introduc.htm
#include<iostream>
#include<boost/tokenizer.hpp>
#include<string>
int main(){
using namespace std;
using namespace boost;
string s = "This is, a test";
tokenizer<> tok(s);
for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout << *beg << "\n";
}
}
The default TokenizerFunction is char_delimiters_separator<char> which defaults to breaking up a string based on space and punctuation.
用 space 跟 ',' 分割 "This is , a test" 應該會得到 "This" "is" "a" "test"
Tokenizer 還有其它用法, 有char_separator,escaped_list_separator,offset_separator,官網上有更詳細的介紹.
http://www.boost.org/libs/tokenizer/index.html
沒有留言:
張貼留言