• <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) 評(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)論排行榜

            久久精品国产男包| 久久午夜免费视频| 97精品久久天干天天天按摩| 久久精品国产99国产电影网| 亚洲Av无码国产情品久久| 国产精品成人久久久久三级午夜电影| 久久久久亚洲av成人网人人软件| 狼狼综合久久久久综合网| 一级做a爰片久久毛片看看| 久久久久久A亚洲欧洲AV冫| 国产高潮久久免费观看| 日韩精品久久无码人妻中文字幕 | 91精品国产9l久久久久| 久久人人爽人人爽AV片| 中文字幕一区二区三区久久网站| 久久超乳爆乳中文字幕| 精品久久久久久久| 人妻少妇久久中文字幕一区二区| 久久亚洲中文字幕精品一区| 69SEX久久精品国产麻豆| 一本色综合网久久| 久久亚洲AV成人出白浆无码国产| 99久久综合国产精品免费 | 久久天天躁夜夜躁狠狠| 久久精品亚洲欧美日韩久久| 久久久精品午夜免费不卡| 青青草原综合久久大伊人精品| 亚洲人成精品久久久久| 日韩精品久久久久久久电影| 狠狠色综合网站久久久久久久| 久久综合精品国产一区二区三区| 精品国产福利久久久| 亚洲国产二区三区久久| 国产精品成人99久久久久| 欧美综合天天夜夜久久| 青青草国产精品久久| 国产精品99久久不卡| 久久性生大片免费观看性| 欧美激情精品久久久久久久| 久久天天躁狠狠躁夜夜2020一| 久久人人爽人人人人片av|