3.2.2 string对象上的操作-两个string对象及字面值和string对象相加

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qit1314/article/details/90047074

书中页数:P80
代码名称:string_add.cc

#include <iostream>
using std::cout; using std::endl;

#include <string>
using std::string;

int main() 
{

	string s1  = "hello, ", s2 = "world\n";
	string s3 = s1 + s2;   // s3 is hello, world\n
	cout << s1 << s2 << s3 << endl;

	s1 += s2;   // equivalent to s1 = s1 + s2
	cout << s1;
	
	string s4 = "hello", s5 = "world";  // no punctuation in s4 or s2
	string s6 = s4 + ", " + s5 + '\n';
	cout << s4 << s5 << "\n" << s6 << endl;
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qit1314/article/details/90047074
今日推荐