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