关闭

Sample 4.8:strtype2.cpp

288人阅读 评论(0) 收藏 举报
分类:
#include<iostream>
#include<string>
int main()
{
    using namespace std;
    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 strtings.\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;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36496次
    • 积分:979
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:63篇
    • 译文:0篇
    • 评论:1条
    文章存档
    最新评论