• <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)  編輯 收藏 引用

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            91超碰碰碰碰久久久久久综合| 成人亚洲欧美久久久久| 伊人久久综合成人网| 无码精品久久久天天影视| 久久精品9988| 久久天天婷婷五月俺也去| 国产成年无码久久久免费| 99久久无码一区人妻| 一本久道久久综合狠狠爱| 久久亚洲综合色一区二区三区| 国产精品久久亚洲不卡动漫| 国产精品一区二区久久精品无码| 久久精品人人做人人爽电影蜜月| 精品久久久久久久无码| 久久免费视频6| 久久精品无码专区免费青青| 久久综合视频网站| 久久狠狠色狠狠色综合| 色婷婷久久综合中文久久蜜桃av| 亚洲午夜精品久久久久久浪潮 | 久久久久久狠狠丁香| 久久无码国产| 亚洲一本综合久久| 久久亚洲私人国产精品vA| 亚洲七七久久精品中文国产| 麻豆精品久久久一区二区| 精品久久人妻av中文字幕| 亚洲中文久久精品无码| 精品伊人久久久| 久久婷婷色综合一区二区| 久久强奷乱码老熟女网站| 香蕉久久久久久狠狠色| 亚洲欧美另类日本久久国产真实乱对白 | 久久免费精品一区二区| 精品国产乱码久久久久久呢| 亚州日韩精品专区久久久| 亚洲午夜无码久久久久小说| 麻豆av久久av盛宴av| 伊人久久大香线蕉综合5g| 亚洲伊人久久精品影院| 久久亚洲国产成人精品性色|