• <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)  編輯 收藏 引用
             
            精品无码人妻久久久久久| 久久精品国产亚洲αv忘忧草| 亚洲精品乱码久久久久久自慰 | 久久久久亚洲精品天堂| 久久久亚洲欧洲日产国码二区 | 国产无套内射久久久国产| 国产精品久久久久久久午夜片| 久久99久久成人免费播放| 久久久久se色偷偷亚洲精品av| 999久久久无码国产精品| 久久亚洲2019中文字幕| 久久久噜噜噜www成人网| 久久久久亚洲?V成人无码| 色综合久久久久无码专区| 欧美激情精品久久久久久久| 久久久久久国产精品无码超碰| 色偷偷91久久综合噜噜噜噜| 国产91色综合久久免费| 久久综合亚洲色HEZYO社区| 国产精品免费久久久久电影网| 久久综合给合久久国产免费| 欧美国产精品久久高清| 精品久久久久久无码人妻热| 久久精品人人做人人爽电影蜜月| 午夜精品久久久久久影视riav| 久久婷婷国产麻豆91天堂| 国产精品久久午夜夜伦鲁鲁| 日本精品久久久久久久久免费| 青青青伊人色综合久久| 精品久久久噜噜噜久久久| 久久综合狠狠综合久久| 狠狠色婷婷久久综合频道日韩| 亚洲国产精品嫩草影院久久| 岛国搬运www久久| 99久久亚洲综合精品成人| 国产一区二区精品久久| av午夜福利一片免费看久久| 色婷婷综合久久久久中文| 亚洲av日韩精品久久久久久a| 亚洲精品高清国产一线久久| 伊人色综合久久天天人手人婷|