第十八章 4string 字符串的合并

#include <iostream>

#include <string>

using namespace std;

int main()

{

	//char字符数组的的合并

	char ch1[40] = "what's your name ";

	char ch2[] = "my name is jack";

	strcat(ch1,ch2);

	cout<<"ch1:"<<ch1<<endl;

	cout<<"ch2:"<<ch2<<endl<<endl<<endl;



	//string类字符串的合并

	string str1 = "what's your name ";

	string str2 = "my name is jack";

	str1= str1 + str2;

	cout<<"str1:"<<str1<<endl;

	cout<<"str2:"<<str2<<endl;



	cout<<strlen(str1.c_str())<<endl;

	//将一个string对像转换为char字符串数组



	cout<<"str1.size:"<<str1.size()<<endl;

	cout<<"str2.size:"<<str2.size()<<endl;







	cout<<"str1.strlen:"<<str1.length()<<endl;

	cout<<"str2.strlen:"<<str2.length()<<endl;





	string str3;

	cout<<"str3.size:"<<str3.size()<<endl;



	

	return 0;

}

  

你可能感兴趣的:(String)