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

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              117 Posts :: 2 Stories :: 61 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(8)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            第一個(gè)程序:string與char[]數(shù)組的對(duì)比。

            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <string>    //make string class available
            using namespace std;
            int main(int argc, char* argv[])
            {
                
            char charr1[20];
                
            char charr2[20]="jaguar";
                
            string str1;
                
            string str2="panther";

                cout
            <<"Enter a kind of feline: ";
                cin
            >>charr1;
                cout
            <<"Enter another kind of feline: ";
                cin
            >>str1;
                cout
            <<"Here are som felines:\n";
                cout
            <<charr1<<" "<<charr2<<" "<<str1<<" "<<str2<<endl;
                cout
            <<"The third letter in "<<charr2<<" is "<<charr2[2]<<endl;
                cout
            <<"The third letter in "<<str2<<" is "<<str2[2]<<endl;
                
            return 0;
            }


            第二個(gè)程序:賦值、拼接和附加

            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <string>
            using namespace std;
            int main(int argc, char* argv[])
            {
                
            string s1="penguin";
                
            string s2,s3;
                cout
            <<"You can assign one string object to another: s2=s1\n";
                s2
            =s1;
                cout
            <<"s1: "<<s1<<", s2: "<<s2<<endl;
                cout
            <<"You can assign a C-style string to a string object.\n";
                cout
            <<"s2=\"buzzard\"\n";
                s2
            ="buzzard";
                cout
            <<"s2: "<<s2<<endl;
                cout
            <<"You can concatenate strings: s3=s1+s2\n";
                s3
            =s1+s2;
                cout
            <<"s3: "<<s3<<endl;
                cout
            <<"You can append strings.\n";
                s1
            +=s2;
                cout
            <<"s1+=s2 yields s1 = "<<s1<<endl;
                s2
            +=" for a day";
                cout
            <<"s2 += \" for a day\" yields s2 = "<<s2<<endl;
                
            return 0;
            }


            第三個(gè)程序:string對(duì)象的技術(shù)和用于字符數(shù)組的技術(shù)的對(duì)比

            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <string>    //make string class available
            #include <cstring>    //C-style string library
            using namespace std;
            int main(int argc, char* argv[])
            {
                
            char charr1[20];
                
            char charr2[20]="jaguar";
                
            string str1;
                
            string str2="panther";

                
            //assignment for string objects and character arrays
                str1=str2;    //copy str2 to str1
                strcpy(charr1,charr2);    //copy charr2 to charr1

                
            //appending for string objects and character arrays
                str1 +=" paste";    //add paste to end of str1
                strcat(charr1," juice");    //add juice to end of charr1

                
            //finding the length of a string object and a C-style string
                int len1=str1.size();    //obtain length of str1
                int len2=strlen(charr1);    //obtain lenght of charr1
                cout<<"The string \""<<str1<<"\" contains "<<len1<<" characters.\n";
                cout
            <<"The string \""<<charr1<<"\" contains "<<len2<<" characters.\n";

                
            return 0;
            }


            第四個(gè)程序,字符串比較問題

            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <string>
            using namespace std;
            int main(int argc, char* argv[])
            {
                
            string word="?ate";

                
            for(char ch='a';word!="mate";ch++)
                
            {
                    cout
            <<word<<endl;
                    word[
            0]=ch;
                }

                cout
            <<"After loop ends,word is "<<word<<endl;
                
            return 0;
            }

            posted on 2010-02-05 21:12 煙皚 閱讀(280) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++ primer plus學(xué)習(xí)筆記
            久久久久久久久久久久中文字幕| 久久精品综合网| 97精品久久天干天天天按摩| 国内精品久久久久久久影视麻豆| 久久无码专区国产精品发布| 久久99精品综合国产首页| 久久精品人妻中文系列| 国产99久久久国产精品~~牛| 亚洲色欲久久久综合网| 亚洲精品乱码久久久久久不卡| 99久久精品日本一区二区免费| 久久免费看黄a级毛片| 天天爽天天狠久久久综合麻豆| 思思久久99热免费精品6| 国内精品久久久久影院优| 久久国产成人午夜aⅴ影院| 久久久国产打桩机| 一本色道久久88加勒比—综合| 国产精品美女久久久| 伊人久久精品影院| 国产精品九九久久免费视频 | 精品久久久久久国产91| 亚洲AⅤ优女AV综合久久久| 色综合久久综精品| 91精品国产色综久久| 国产亚洲精品久久久久秋霞| 久久久久久国产精品免费免费| 久久精品无码专区免费| 97久久精品无码一区二区天美 | aaa级精品久久久国产片| 国产成人无码精品久久久性色 | 亚洲精品tv久久久久久久久| 亚洲国产精品无码久久九九| 久久久久国产一区二区| 91精品国产91久久| 婷婷综合久久狠狠色99h| 国内精品久久国产大陆| 久久96国产精品久久久| 久久精品亚洲精品国产色婷| 久久久久久久97| 狠狠色丁香婷综合久久|