string定义及构造函数

#include<iostream>
#include<string>
using namespace std;

int main(){
string str;
cout<<str<<""<<str.empty()<<endl; //用str.empty检测字符串是否为空 (0,1)
cout<<str<<endl; //无参数

string str1(5,'a'); //给str5个字符a
cout<<str1<<""<<str1.empty()<<endl;
cout<<str1<<endl;

string str2("abcde"); //字符串初始化
cout<<str2<<endl;

string str3("abcde",3); //str的前几个
cout<<str3<<endl;

string str4(str2,2,3); //str中间几个
cout<<str4<<endl;

string str5(str2); //str的拷贝构造
cout<<str5<<endl;

system("pause");
return 0;
}

原文地址:https://www.cnblogs.com/huoyuying/p/9660281.html