• <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 - 分解字串,提取內容.作者: 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 張沈鵬 閱讀(750) 評論(0)  編輯 收藏 引用
             
            精品久久无码中文字幕| 久久免费香蕉视频| 色88久久久久高潮综合影院| 久久久精品久久久久影院| 奇米影视7777久久精品人人爽| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 欧美一级久久久久久久大| 亚洲国产成人久久综合一区77| 久久无码专区国产精品发布| 久久w5ww成w人免费| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲一区精品伊人久久伊人| 天天爽天天狠久久久综合麻豆| 国产婷婷成人久久Av免费高清| 日韩一区二区久久久久久| 久久精品无码一区二区三区免费| 亚洲伊人久久精品影院| 国产精品熟女福利久久AV| 国内精品伊人久久久影院| 欧美一区二区精品久久| 久久人人爽人人爽人人片AV不| 欧洲国产伦久久久久久久| 麻豆一区二区99久久久久| 久久男人AV资源网站| 久久婷婷五月综合色高清| 欧美久久久久久| 国内精品久久久久久麻豆 | 伊人久久精品影院| 中文成人久久久久影院免费观看| 久久久久免费精品国产| 精品无码久久久久久午夜| 成人久久免费网站| 麻豆成人久久精品二区三区免费 | 久久线看观看精品香蕉国产| 亚洲AV无码1区2区久久| 亚洲国产成人乱码精品女人久久久不卡 | 亚洲精品国产自在久久| 久久99亚洲综合精品首页| 青草影院天堂男人久久| 国产国产成人精品久久| 国产午夜久久影院|