> 文章列表 > C++ primer plus(第六版)编程练习答案 第16章 string类和标准模板库

C++ primer plus(第六版)编程练习答案 第16章 string类和标准模板库

C++ primer plus(第六版)编程练习答案 第16章 string类和标准模板库

一、程序清单

str1.cpp 

// str1.cpp -- introducing the string class
#include <iostream>
#include <string>
// using string constructorsint main()
{using namespace std;string one(\"Lottery Winner!\");     // ctor #1cout << one << endl;               // overloaded <<string two(20, \'$\');               // ctor #2cout << two << endl;string three(one);                 // ctor #3cout << three << endl;one += \" Oops!\";                   // overloaded +=cout << one << endl;two = \"Sorry! That was \";three[0] = \'P\';string four;                       // ctor #4four = two + three;                // overloaded +, =cout << four << endl;char alls[] = \"All\'s well that ends well\";string five(alls, 20);              // ctor #5cout << five << \"!\\n\";string six