• <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>

            linux&c++ R&D

            programing is a pleasure!

            How to express string semantic (2)?

            (2)string  and related  classes in  c++ STL 
            string class  is a portable class.it can be used in many platforms,such as windows,linux,unix,etc!
            it encapsulates string semantic and provides many useful member fuctions !
            when we use it, don't worry memory overflow,beause it can allocate memory space itself.
            In STL,it is defined in header <string>  and std namespace.so if you use it, you will add
            #include <string> and
            using std::string;or
            using std::namespace or
            in programe use
            std::string define string.
            for example:
            #include <string>
            #include 
            <iostream>
            int main()
            {
              std::string str;
              std::cin
            >>str;
              std::cout
            <<"your input:"<<str<<std::endl; 
            }
            member funtions in string is very useful.
            I  won't discuss it in detail,for many good books do it!
            Although string class isn't a container class,it provides similar interfaces,such as begin(),end().
            so you can use it like a container class so it can agree with many generic algorithm  in header <algorithm> .
            for example:
            string str1( "Alpha Beta Gamma Delta" );
               string::size_type loc 
            = str1.find( "Omega"0 );
               
            if( loc != string::npos ) {
                 cout 
            << "Found Omega at " << loc << endl;
               }
             else {
                 cout 
            << "Didn't find Omega" << endl;         
               }

            or
            string str1( 
            "Alpha Beta Gamma Delta" );
               string::const_iterator loc 
            = find( str1.begin(),str1.end(),"Omega");
               
            if( loc != str1.end() ) {
                 cout 
            << "Found Omega at " << loc << endl;
               }
             else {
                 cout 
            << "Didn't find Omega" << endl;         
               }

            and so on!
            some useful associated classes are introduced here.
            they are defined in header <sstream>:
          1. stringstream - allows input and output
          2. istringstream - allows input only
          3. ostringstream - allows output only

            An ostringstream object can be used to write to a string. This is similar to the C sprintf() function. For example:
             

             ostringstream s1;
              
            int i = 22;
              s1 
            << "Hello " << i << endl;
              string s2 
            = s1.str();
              cout 
            << s2;


            An istringstream object can be used to read from a string. This is similar to the C sscanf() function. For example:
             

             istringstream stream1;
            string string1 
            = "25";
              stream1.str(string1);
              
            int i;
              stream1 
            >> i;
              cout 
            << i << endl;  // displays 25


              You can also specify the input string in the istringstream constructor as in this example:

             string string1 = "25";
              istringstream stream1(string1);
              
            int i;
              stream1 
            >> i;
              cout 
            << i << endl;  // displays 25

             A stringstream object can be used for both input and output to a string like an fstream object.

             when you are familar with these classes,you are able to handle with string-related problem!

          4. posted on 2007-04-20 23:46 丑石 閱讀(803) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            国产美女亚洲精品久久久综合| 一本色道久久99一综合| 情人伊人久久综合亚洲| 久久国产精品国语对白| 欧美久久一区二区三区| 亚洲愉拍99热成人精品热久久| 无码专区久久综合久中文字幕| 久久九九全国免费| 伊人久久大香线蕉综合Av| 国产一区二区三精品久久久无广告| 久久久久久亚洲精品无码| 久久婷婷五月综合色奶水99啪| 91精品免费久久久久久久久| 色诱久久久久综合网ywww| 精品国产乱码久久久久久浪潮 | 一本久久a久久精品vr综合| 久久91精品国产91久久小草 | 青草国产精品久久久久久| 国产亚洲色婷婷久久99精品91| 久久偷看各类wc女厕嘘嘘| 亚洲欧洲精品成人久久曰影片 | 欧美国产成人久久精品| 国产综合久久久久久鬼色| 国产香蕉久久精品综合网| 久久精品国产黑森林| 久久精品国产免费| 久久精品成人国产午夜| 久久久久成人精品无码中文字幕 | 久久久久国产精品| 奇米影视7777久久精品| 久久中文字幕人妻熟av女| 伊人热人久久中文字幕| 精品国际久久久久999波多野| 久久久无码精品亚洲日韩京东传媒| 久久99国产一区二区三区| 日本一区精品久久久久影院| 久久免费视频观看| 青青青伊人色综合久久| 国产高清国内精品福利99久久| 日韩一区二区久久久久久| 99久久婷婷国产一区二区|