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

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久久久无码中文字幕| 精品久久久久久中文字幕人妻最新| 久久久久人妻一区二区三区vr| 99久久er这里只有精品18| 国产精品久久久久久久app| 久久精品国产亚洲AV忘忧草18| 72种姿势欧美久久久久大黄蕉| 国产91久久精品一区二区| 国产高清美女一级a毛片久久w| 欧美黑人又粗又大久久久 | 欧美性大战久久久久久| 色妞色综合久久夜夜| 久久99国产精品尤物| 亚洲国产成人久久一区久久| 久久精品视频免费| 一本色道久久99一综合| 久久久无码精品亚洲日韩京东传媒 | 精品久久久久久无码人妻热 | 久久综合给久久狠狠97色| 久久久精品国产Sm最大网站| 99久久精品国内| 久久久久久久久66精品片| 久久99精品久久久久久野外| 久久久久久国产精品无码超碰 | 久久久WWW免费人成精品| 精品少妇人妻av无码久久| 亚洲人成网站999久久久综合 | 狠狠色丁香婷婷综合久久来| 亚洲AV日韩精品久久久久| 久久免费的精品国产V∧| 久久久国产视频| 久久一本综合| 国产精品久久久久久五月尺| 精品久久久久久久久久中文字幕| 国产精品毛片久久久久久久| 人妻精品久久无码区| 亚洲中文字幕无码久久综合网| 久久这里都是精品| 午夜精品久久久久久久无码| 国产精品免费久久久久影院| 91精品国产高清久久久久久国产嫩草|