• <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 類時須包含這個文件
            #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字符轉換
                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;

                
            //  求字符串的長度
                string str5;
                cout 
            << "輸入字符串 str5" << endl;
                cin 
            >> str5;
                
            int   len= str5.size();
                cout 
            << "字符串 str5的長度為" << 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;

                
            //  比較兩個字符串   比較規則同 c字符串比較規則
                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;
                
                
            //  字符串是否包含子串  如果包含 則返回子串在目標串中第一次出現的位置 
                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;
                
                
            //  轉換成 c_字符串
                string str15= "Hello World";
                printf(
            "%s\n", str15.c_str() );
                 
                system(
            "pause"); 

                
            return 0;
            }
            posted on 2009-03-13 17:01 Darren 閱讀(25160) 評論(0)  編輯 收藏 引用
            婷婷久久五月天| 久久亚洲av无码精品浪潮| 无码人妻精品一区二区三区久久| 亚洲欧美一区二区三区久久| 性欧美大战久久久久久久久| 日韩精品国产自在久久现线拍| 亚洲v国产v天堂a无码久久| 亚洲va久久久噜噜噜久久| 久久综合九色综合久99| 思思久久99热只有频精品66| 九九99精品久久久久久| 四虎影视久久久免费| 69国产成人综合久久精品| 日本加勒比久久精品| 亚洲国产二区三区久久| 亚洲综合伊人久久大杳蕉| 99久久精品费精品国产| 色妞色综合久久夜夜| 久久亚洲电影| 久久久精品波多野结衣| 久久精品国产91久久麻豆自制| 久久久久久精品无码人妻| 久久精品国产精品亚洲下载| 久久免费视频观看| 国产精品一区二区久久| 久久精品国产第一区二区三区| 亚洲国产精品嫩草影院久久| 久久婷婷久久一区二区三区| 91精品国产综合久久精品| 久久综合给久久狠狠97色| 国产毛片欧美毛片久久久| 国产精品乱码久久久久久软件| 欧美大战日韩91综合一区婷婷久久青草 | 伊人久久精品无码av一区| 久久久久久国产a免费观看不卡| 久久国产乱子精品免费女| 青青草原综合久久| 国内精品欧美久久精品| 久久精品18| 久久精品久久久久观看99水蜜桃| 久久久久久精品成人免费图片|