#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1;
string str2 = "www.sikiedu.com";
cout<<str1<<endl;
cout<<str2<<endl;
str1=str2;
cout<<str1<<endl;
cin>>str1;
cout<<str1<<endl;
return 0;
}
输出:
www.sikiedu.com
www.sikiedu.com
siki edu
siki
请按任意键继续. . .
getline(cin,str1);
cout<<str1<<endl;
输入:
siki edu
sikiedu
请按任意键继续. . .
cout<<str2[5]<<endl; // 输出:i
st1="sikiedu";
str2=".com";
string s = str1+str2; // 字符串的组拼
s+=str1; // s=s+str1; // s=s+str1; sikiedu.com + sikiedu sikiedu.comsikiedu
cout<<s<<endl;
cout<<s.size()<<endl; // 输出:11 // 字符串的大小
//string s = "sikiedu" + ".com"