字符串拼接

去除尾部多余的字符

 

#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;
}

去除,

posted @ 2014-08-20 10:12  westfly  阅读(141)  评论(0编辑  收藏  举报