char *c = new char[100];
strlen©
上述结果居然是104 //VS2017 MSVC;
std::string ss = c;
这样构造, ss string.length依然是104;
转string 建议用第二种构造方法:
std::string(c, size);
这样才不会构造有误;
特别注意C风格字符串申请内存的时候多new一个字节,如:
char *c = new char[101];
memset(c, 0, 100)
这样strlen碰到最后一个0自然就返回了100。