• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            boost在路上...tokenizer
            tokenizer - Break of a string or other character sequence into a series of tokens, from John Bandela
            tokenizer - 分解字串,提取內(nèi)容.作者: John Bandela

            例一:
            // simple_example_1.cpp
            #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";
               }
            }

            輸出
            This
            is
            a
            test

            tokenizer默認將單詞以空格和標點為邊界分開.

            例二:
            #include<iostream>
            #include<boost/tokenizer.hpp>
            #include<string>

            int main(){
               using namespace std;
               using namespace boost;
               string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
               tokenizer<escaped_list_separator<char> > tok(s);
               for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
                   cout << *beg << "\n";
               }
            }
            輸出
            Field 1
            putting quotes around fields, allows commas
            Field 3

            雙引號之間可以有標點.


            例三:
            // simple_example_3.cpp
            #include<iostream>
            #include<boost/tokenizer.hpp>
            #include<string>

            int main(){
               using namespace std;
               using namespace boost;
               string s = "12252001";
               int offsets[] = {2,2,4};
               offset_separator f(offsets, offsets+3);
               tokenizer<offset_separator> tok(s,f);
               for(tokenizer<offset_separator>::iterator beg=tok.begin(); beg!=tok.end();++beg){
                   cout << *beg << "\n";
               }
            }

            把12252001分解為
            12
            25
            2001

            例4:
            // char_sep_example_1.cpp
            #include <iostream>
            #include <boost/tokenizer.hpp>
            #include <string>

            int main()
            {
              std::string str = ";!!;Hello|world||-foo--bar;yow;baz|";
              typedef boost::tokenizer<boost::char_separator<char> >
                tokenizer;
              boost::char_separator<char> sep("-;|");
              tokenizer tokens(str, sep);
              for (tokenizer::iterator tok_iter = tokens.begin();
                   tok_iter != tokens.end(); ++tok_iter)
                std::cout << "<" << *tok_iter << "> ";
              std::cout << "\n";
              return EXIT_SUCCESS;
            }

            輸出
            <!!> <Hello> <world> <foo> <bar> <yow> <baz>
            自定義分隔的標點

            例5:
                // char_sep_example_2.cpp
                #include <iostream>
                #include <boost/tokenizer.hpp>
                #include <string>

                int main()
                {
                    std::string str = ";;Hello|world||-foo--bar;yow;baz|";
                    typedef boost::tokenizer<boost::char_separator<char> >
                        tokenizer;
                    boost::char_separator<char> sep("-;", "|", boost::keep_empty_tokens);
                    tokenizer tokens(str, sep);
                    for (tokenizer::iterator tok_iter = tokens.begin();
                         tok_iter != tokens.end(); ++tok_iter)
                      std::cout << "<" << *tok_iter << "> ";
                    std::cout << "\n";
                    return EXIT_SUCCESS;
                }

            The output is:

                <> <> <Hello> <|> <world> <|> <> <|> <> <foo> <> <bar> <yow> <baz> <|> <>
            去除-; , 保留|但將它看作是分隔符,當兩個分隔符相鄰的時候會自動加空格

            例6:
                // char_sep_example_3.cpp
                #include <iostream>
                #include <boost/tokenizer.hpp>
                #include <string>

                int main()
                {
                   std::string str = "This is,  a test";
                   typedef boost::tokenizer<boost::char_separator<char> > Tok;
                   boost::char_separator<char> sep; // default constructed
                   Tok tok(str, sep);
                   for(Tok::iterator tok_iter = tok.begin(); tok_iter != tok.end(); ++tok_iter)
                     std::cout << "<" << *tok_iter << "> ";
                   std::cout << "\n";
                   return EXIT_SUCCESS;
                }

            The output is:

                <This> <is> <,> <a> <test>
            保留標點但將它看作分隔符

            posted on 2006-01-25 18:00 張沈鵬 閱讀(747) 評論(0)  編輯 收藏 引用
             
            国产精品久久久久…| 中文字幕精品久久久久人妻| 久久国产精品无码一区二区三区| 午夜久久久久久禁播电影| 久久精品这里热有精品| 精品99久久aaa一级毛片| 亚洲精品高清一二区久久| 伊人久久综合无码成人网| 国产精品久久波多野结衣| 久久久久国色AV免费观看| 久久人人爽人人爽人人片av麻烦| 色综合久久无码五十路人妻| 亚洲国产精品久久| 亚洲AV无一区二区三区久久| 狠狠色综合网站久久久久久久| 久久久久久精品久久久久| 久久成人精品| 国产精品18久久久久久vr| 奇米影视7777久久精品人人爽| 久久精品9988| 2021久久精品国产99国产精品| 亚洲?V乱码久久精品蜜桃| 国产成人久久精品区一区二区| 午夜精品久久久久成人| 精品久久久久久国产牛牛app| 久久人妻少妇嫩草AV无码专区| 狠狠色丁香婷婷久久综合| 国产AV影片久久久久久| 久久国产精品99精品国产987| 色婷婷综合久久久中文字幕| 99久久做夜夜爱天天做精品| 久久99精品国产99久久6| 久久精品国产亚洲AV无码麻豆| 亚洲∧v久久久无码精品| 亚洲国产天堂久久久久久| 国产—久久香蕉国产线看观看 | 久久97久久97精品免视看| 99久久精品国产一区二区| 99久久久精品免费观看国产| 国产精品久久久久久| 久久精品国产免费|