const char* c_str ( ) const;
Get C string equivalent
Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.
A terminating null character is automatically appended. const char* data() const;
Get string data
Returns a pointer to an array of characters with the same content as the string.
Notice that no terminating null character is appended (see member c_str for such a functionality).

  

c_str()字符串后有'\0',而data()没有

简单的const string 转void*

#include <iostream>
using namespace std; int main()
{
const string c = "90908080";
const char* buf = c.c_str();
char* tmp = const_cast<char*> (buf);
cout<<buf<<endl;
cout<<tmp<<endl;
void* v=reinterpret_cast<void*>(tmp);
cout<<v<<endl;
cout<<(char*)(v)<<endl;
return 0;
}

  

最新文章

  1. 从为什么String=String谈到StringBuilder和StringBuffer
  2. Dancing Links初学记
  3. EF查询分页
  4. Javascript之clipBoard操作
  5. 踩到两只“bug”
  6. 曾经的岁月之maya
  7. [转载]jquery的extend和fn.extend
  8. 文本编辑BOM标记(Byte Order Mark)
  9. KSImageNamed-Xcode
  10. 整理了一份React-Native学习指南
  11. An Easy Problem?!(细节题,要把所有情况考虑到)
  12. The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
  13. php 表单提交大量数据发生丢失的解决方法
  14. HDU-6153 A Secret 扩展KMP
  15. Kettle系列: Kettle并行执行Trans后的合并问题
  16. pacman 命令
  17. ELK日志收集
  18. ARM40-A5应用——fbset与液晶屏参数的适配【转】
  19. 关于redis与memcached区别(转载自stackoverflow)
  20. SharePoint 解决管理员密码修改后各种问题的来袭

热门文章

  1. 利用Turtle绘制各种图形
  2. SpringBoot整合Elasticsearch游标查询(scroll)
  3. JavaWeb学习笔记(六)jsp
  4. ssh执行命令
  5. git常见操作和指令
  6. slf4j --&gt;log4j --&gt; logback --&gt;log4j2
  7. 一个基于canvas的移动端图片编辑器
  8. H5页面字体设置
  9. FFmpeg滤镜使用
  10. 从创建进程到进入main函数,发生了什么?