c_str

来源:互联网 发布:icloud优化存储空间 编辑:程序博客网 时间:2024/06/06 00:43

c_str返回一个字符串的指针(它的地址),内容和string类的本身对象是一样的,

string类c_str函数原型: const char *c_str()const;//返回一个以null终止的c字符串


  char* c;

  string s="1234";

  c = s.c_str(); //c最后指向的内容是垃圾,因为s对象被析构,其内容被处理

  

可读不可改
0 0
原创粉丝点击