算法笔记-字符串

字符串拼接

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(int argc,char * argv[]){
	string s="abc";
	
	// ----- 字符串拼接字符串 ----- 
	
	s+=to_string(10); 
	s.append("def");
	s.append(to_string(11));
	printf("%s",s.c_str());
	
	// -----  字符串拼接字符 ----- 
	
	s+='g';
//	s.append('h'); error 

	//  ----- 字符串拼接单个数字 ----- 
	
//	s.append(1); error
	s+=2+'0';
//	s.append(3+'0'); error
	s.append(to_string(4));
	printf("%s",s.c_str());
	
	
	//  ----- 字符串拼接多位数字 ----- 
	
//	s+=12+'0'; error ascii码中 没有12这个字符,12+'0' 不是'12' 
//	s.append(12);error
//	s+12; error
	s.append(to_string(12));
	s+=to_string(234);
	printf("%s",s.c_str());
	return 0;
} 
原文地址:https://www.cnblogs.com/houzm/p/13335185.html