• <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;

                
            //  求字符串的長度
                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;

                
            //  比較兩個(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 閱讀(25160) 評論(0)  編輯 收藏 引用

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


            品成人欧美大片久久国产欧美...| 久久精品国产亚洲AV无码偷窥| 亚洲精品无码专区久久久| 韩国三级中文字幕hd久久精品| 久久久精品人妻一区二区三区四| 人人妻久久人人澡人人爽人人精品 | 久久精品国产久精国产思思| 国内精品久久久久影院薰衣草 | 久久亚洲中文字幕精品有坂深雪 | 久久久久99这里有精品10| 精品久久久久久无码人妻热| a级毛片无码兔费真人久久| 国产精品内射久久久久欢欢| 伊人久久免费视频| 久久性精品| 99久久精品国产一区二区 | 久久综合狠狠综合久久| 亚洲AV无码久久精品色欲| 看久久久久久a级毛片| 久久91精品国产91久久户| 久久国产精品免费| 久久婷婷五月综合国产尤物app| 精品一二三区久久aaa片| 久久精品人人做人人爽97 | 久久久久波多野结衣高潮| 亚洲午夜久久久影院| 麻豆精品久久精品色综合| 性做久久久久久久久老女人| 无码AV中文字幕久久专区| 一本久久久久久久| 久久这里的只有是精品23| 久久成人影院精品777| 色8激情欧美成人久久综合电| 伊人久久无码中文字幕| 91精品国产91久久久久久蜜臀| 亚洲欧美另类日本久久国产真实乱对白| 亚洲αv久久久噜噜噜噜噜| 中文字幕亚洲综合久久| 亚洲人成伊人成综合网久久久| 久久精品国产精品亚洲精品| 一本大道久久香蕉成人网|