C++笔记——标准库类型string

来源:互联网 发布:高效程序员的45个 pdf 编辑:程序博客网 时间:2024/05/23 19:20

需加头文件 #include <string>

字符串对象的初始化方法:




#include<string>using namespace::std;int main(){    string a("c++");    string b(a);    string c(4,'a');    cout << a << endl;    cout << b << endl;    cout << c << endl;    string d;    d = a;    if(d.empty())    {        cout << "string d is empty" << endl;    }    else    {        cout << "string d's size is " << d.size() << endl;    }    string e = a + c;    cout << e << endl;    if(e == a)    {        cout << "e equals a" << endl;    }else    {        cout << "e doesn't equal a" << endl;    }    return 0;}


原创粉丝点击