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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM