• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              117 Posts :: 2 Stories :: 61 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(8)

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            第一個程序:string與char[]數組的對比。

            #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;
            }


            第二個程序:賦值、拼接和附加

            #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;
            }


            第三個程序:string對象的技術和用于字符數組的技術的對比

            #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;
            }


            第四個程序,字符串比較問題

            #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 煙皚 閱讀(287) 評論(0)  編輯 收藏 引用 所屬分類: C++ primer plus學習筆記
            久久久久国产精品麻豆AR影院| 亚洲欧洲中文日韩久久AV乱码| 东京热TOKYO综合久久精品| 久久99国产乱子伦精品免费| 国产精品久久久99| 亚洲狠狠婷婷综合久久蜜芽 | 久久精品国产亚洲AV无码娇色| 97久久精品无码一区二区| 污污内射久久一区二区欧美日韩| 久久精品人人做人人爽97| 欧美国产成人久久精品| 成人久久精品一区二区三区| 国产精品久久久久久五月尺| 999久久久免费国产精品播放| 久久AV无码精品人妻糸列| 久久精品亚洲男人的天堂| 久久99精品久久只有精品| 天天影视色香欲综合久久| 伊人久久大香线焦综合四虎| 亚洲乱码中文字幕久久孕妇黑人| 久久久久亚洲AV成人网人人网站 | 韩国无遮挡三级久久| 久久综合国产乱子伦精品免费| 久久se精品一区二区影院 | 久久偷看各类wc女厕嘘嘘| 一本久久免费视频| 久久夜色精品国产www| 久久久久成人精品无码| 国产呻吟久久久久久久92| 热99re久久国超精品首页| 欧美久久综合性欧美| 久久国产高清字幕中文| 久久精品这里热有精品| 久久精品成人国产午夜| 亚洲精品高清久久| 国产毛片久久久久久国产毛片 | 大香伊人久久精品一区二区| 亚洲欧洲久久av| 无码国内精品久久人妻| 人妻无码久久一区二区三区免费| 久久久精品人妻一区二区三区四|