• <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>
            #include <string>    //  使用 string 類時(shí)須包含這個(gè)文件
            #include <iostream>

            using namespace std;

            int main()
            {
                
            string str1;
               
                
            //  輸入與輸出
                cout << "輸入字符串 str1" << endl;
                cin 
            >> str1; getchar();
                cout 
            << str1 << endl << endl << endl;
                
                
            //  一行行讀取 
                cout << "輸入字符串 str1" << endl;
                getline( cin, str1 );
                cout 
            << str1 << endl;

                
            //  與 c字符轉(zhuǎn)換
                string str2("Hello World!"), str3;
                
            char   str4[50];

                cout 
            << "輸入 C 字符串" << endl;
                scanf(
            "%s",str4);
                str3
            = str4;

                cout 
            << "str2 is " << str2 << endl;
                cout 
            << "str3 is " << str3 << endl << endl << endl;

                
            //  求字符串的長(zhǎng)度
                string str5;
                cout 
            << "輸入字符串 str5" << endl;
                cin 
            >> str5;
                
            int   len= str5.size();
                cout 
            << "字符串 str5的長(zhǎng)度為" << len << endl << endl << endl;

                
            //  遍歷字符串例子
                string str6;
                cout 
            << "輸入字符串 str6" << endl;
                cin 
            >> str6;
                
            int i;
                
            for( i= 0; i< str6.size(); ++i )
                cout 
            << str6[i];
                cout 
            << endl << endl;

                
            //  比較兩個(gè)字符串   比較規(guī)則同 c字符串比較規(guī)則
                string str7, str8;
                cout 
            << "輸入字符串 str7, str8 , 中間用空格格開" << endl;
                cin 
            >> str7 >> str8;

                
            if( str7< str8 ) cout << str7 << "  小于 " << str8 << endl;
                
            else if( str7> str8 ) cout << str7 << "  大于 " << str8 << endl;
                
            else cout << str7 << "  等于 " << str8 << endl;
                
                
                
            //  字符串與字符相加 
                string str9= "Darren";
                
            char ch1= 'a', ch2= 'b';
                str9
            = str9+ ch1; cout << str9 << endl << endl;
                str9
            = ch2+ str9; cout << str9 << endl << endl << endl;
                
                
            //  字符串與字符串相加
                string str10= "Acm", str11= "ICPC";
                str10.append( str11 );
                cout 
            << str10 << endl << endl;
                
                
            //  字符串是否包含子串  如果包含 則返回子串在目標(biāo)串中第一次出現(xiàn)的位置 
                string str12= "I am a student", str13= "student", str14= "aaaaaaa";
                
            if( str12.find( str13 )!= -1 )  cout << "Find " << str13 << endl;
                
            if( str12.find( str14 )== -1 )  cout << "Not Find  " << str14 << endl;
                
                
            //  轉(zhuǎn)換成 c_字符串
                string str15= "Hello World";
                printf(
            "%s\n", str15.c_str() );
                 
                system(
            "pause"); 

                
            return 0;
            }
            posted on 2009-03-13 17:01 Darren 閱讀(25163) 評(píng)論(0)  編輯 收藏 引用

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


            精品国产乱码久久久久久呢| 2019久久久高清456| 国产精品热久久无码av| 久久久99精品一区二区| 中文无码久久精品| 大美女久久久久久j久久| 亚洲欧洲久久av| 久久婷婷国产麻豆91天堂| 日韩va亚洲va欧美va久久| 久久精品草草草| 色综合久久无码五十路人妻| 国产毛片久久久久久国产毛片 | 国产亚洲综合久久系列| 久久免费香蕉视频| 久久这里只有精品18| 久久国产综合精品五月天| 精品久久久久久国产潘金莲| 久久精品国产99国产精品亚洲| 91精品婷婷国产综合久久| 久久99精品久久久久久| 伊人久久综合无码成人网| 亚洲国产成人乱码精品女人久久久不卡 | 久久人妻无码中文字幕| 精品国产91久久久久久久a| 99久久99久久久精品齐齐| 99蜜桃臀久久久欧美精品网站| 欧美精品丝袜久久久中文字幕| 亚洲午夜精品久久久久久人妖| 国产亚洲精品自在久久| 久久AV高清无码| 久久精品亚洲中文字幕无码麻豆| 久久精品青青草原伊人| 色妞色综合久久夜夜| 久久精品一区二区三区AV| 久久无码AV一区二区三区| 亚洲人AV永久一区二区三区久久 | 无码国内精品久久人妻蜜桃 | 99精品久久精品一区二区| 精品久久久无码人妻中文字幕豆芽 | 久久久综合九色合综国产| 久久综合九色综合欧美狠狠|