首页 > 代码库 > 字符串拼接

字符串拼接

去除尾部多余的字符

 

#include <string>#include <stdio.h>int main(int argc, const char *argv[]){    std::string str;    char buf[16];    for (int i = 0; i < 10; i++) {      int len = snprintf(buf, sizeof(buf), "%d,", i);      str.append(buf, len);    }    printf("%s\n", str.c_str());    str.erase(str.size() - 1 );    printf("%s\n", str.c_str());    return 0;}

去除,