欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-15 13:43:11
...

需加头文件 #include <string>

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

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

C++笔记——标准库类型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;
}

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