• <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 丑石 閱讀(801) 評(píng)論(0)  編輯 收藏 引用


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


            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            99国产欧美久久久精品蜜芽| 久久精品一区二区三区AV| 精品国产乱码久久久久久1区2区 | 国产亚洲精久久久久久无码AV| 狠狠狠色丁香婷婷综合久久五月| 亚洲嫩草影院久久精品| 亚洲欧洲久久av| 久久久久四虎国产精品| 久久精品久久久久观看99水蜜桃| 狠狠色丁香婷婷综合久久来| 色欲综合久久躁天天躁| 久久精品成人免费网站| 精品久久久久成人码免费动漫| 99久久精品国内| 久久AV无码精品人妻糸列| 久久久精品日本一区二区三区| 久久婷婷五月综合97色| 思思久久99热只有频精品66| 九九久久99综合一区二区| 日韩人妻无码一区二区三区久久| 久久国产美女免费观看精品| 91精品国产91久久久久福利| 久久婷婷五月综合国产尤物app | 欧美熟妇另类久久久久久不卡 | 一本久道久久综合狠狠躁AV| 久久综合中文字幕| 久久精品国产精品亚洲毛片| 亚洲精品蜜桃久久久久久| 久久人人爽人人爽人人片AV麻豆| 久久精品一区二区国产| 久久综合久久自在自线精品自| 久久精品国产色蜜蜜麻豆| 欧美久久一级内射wwwwww.| 国产ww久久久久久久久久| 久久免费小视频| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久久久九国产精品| 久久91这里精品国产2020| 99久久国产亚洲高清观看2024| 久久亚洲高清观看| 99久久夜色精品国产网站|