#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
string s1 = "ywb";
string s2(s1);
string s3 = s2;
string s4("yangwen");
string s5(10, 'c');
cout << s1 << " " << s2 << " " << s3 << " " << s4 << " " << s5 << endl;
string str("yangwenbin");
int length = str.length();
int length1 = str.size();
cout << length << " " << length1 << endl;
for (int i = 0; i < length1; i++)
{
cout << str.at(i) << " " ;
}
cout << endl;
cout << *str.begin() << endl;
cout << *(str.end() - 1) << endl;;
if (!str.empty())
{
cout << "i am not empty" << endl;;
}
str.resize(length + 10, 'a');
cout << str << endl;;
str.clear();
if (str.empty())
{
cout << "i am empty" << endl;;
}
str.append("ywb");
cout << str << endl;
str.append(" hell0");
cout << str;
system("pause");
}
![C++ string(初始化和部分函数的使用) C++ string(初始化和部分函数的使用)](https://image.shishitao.com:8440/aHR0cHM6Ly93d3cuaXRkYWFuLmNvbS9nby9hSFIwY0RvdkwybHRaeTVpYkc5bkxtTnpaRzR1Ym1WMEx6SXdNVGN3TlRFd01qQXpNakl5TlRnMVAzZGhkR1Z5YldGeWF5OHlMM1JsZUhRdllVaFNNR05FYjNaTU1rcHpZakpqZFZrelRtdGlhVFYxV2xoUmRtTllSbVpOZWxFeVRYcGpNRTFFWnowdlptOXVkQzgxWVRaTU5Vd3lWQzltYjI1MGMybDZaUzgwTURBdlptbHNiQzlKTUVwQ1VXdEdRMDFCUFQwdlpHbHpjMjlzZG1Vdk56QXZaM0poZG1sMGVTOVRiM1YwYUVWaGMzUT0%3D.jpg?w=700&webp=1)