1.STL的截取字符串
string str = "hello world";
str.substr( 0 , 8);
输出:
hello wo
这里的第一个参数是 ,起始的位置,第二个参数是截取的大小
2.char * 的合并
char c[512] = "";
char * c1 = "hello ";
char * c2 = "world";
strcat( c , c1);
strcat( c , c2);
printf("%s" , c);
输出:
hello world
注意这里的 c必须要初始化,因为如果不初始化 不能确定里边到底 初始的是什么东西
3.STL 的trim
void Trim( string& inout_s )
{
// Remove leading and trailing whitespace
static const char whitespace[] = " \n\t\v\r\f";
inout_s.erase( 0, inout_s.find_first_not_of(whitespace) );
inout_s.erase( inout_s.find_last_not_of(whitespace) + 1U );
}
这个函数可以将输入字符串的 空格 换行制表符去掉,并且只去掉头尾的