strlen()

作者: b6aed1af4328 | 来源:发表于2017-06-15 19:18 被阅读29次

strlen()遇”\0“就停止计数,是个坑啊。
今天将二十个字节头append到std::string str中。write时要转为char*,设定起始地址和长度,起始地址用str.c_str(),或者str.data()都可以,但长度用了strlen(str.c_str()),二十字节头,遇"\0"即止...长度应为80的,结果只计为了2...
以后长度用str.length()。

/********************************************************/
被推翻了...

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main()
{
        std::string str2="songshiqi\0xieao";
        printf("%d %d %d\n",str2.length(),str2.size(),strlen(str2.c_str()));
}

相关文章

网友评论

      本文标题:strlen()

      本文链接:https://www.haomeiwen.com/subject/aeuuqxtx.html