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. 2019年CSP-J初赛试题(普及组)试题详解

    https://www.jianshu.com/p/9e58f455c1ee https://blog.csdn.net/weixin_39104847/article/details/1086711 ...

  2. centos8:linux平台查看线程(ps/pstree/top)

    一,ps/pstree/top命令所属的rpm包 pstree所属的包 [root@blog ~]# whereis pstree pstree: /usr/bin/pstree /usr/bin/p ...

  3. phpstorm配置sftp自动上传

    勾选自动上传 手动上传   qq_23049573 原创文章 14获赞 4访问量 2万+ 关注 私信

  4. 使用ModelForm校验数据唯一性

    在设计模型类的时候,将指定字段设置unique=true属性,可以保证该字段在数据库中的唯一性. 使用ModelForm可以将指定模型类快速生成表单元素.在提交数据后,使用is_valid()校验时, ...

  5. npm install各种命令模式

    npm install 几种命令模式: npm install moduleName 安装模块到项目目录下 npm install -g moduleName npm install -g 将模块安装 ...

  6. 想买保时捷的运维李先生学Java性能之 运行时数据区域

    前言 不知道自己不知道,不知道自己知道,知道自己不知道,知道自己知道,目前处于知道自己不知道这个阶段,很痛苦啊,干了4年了运维,是一个坎.越来越发觉想要走得远,还是得扎根底.   一.运行时数据区域 ...

  7. java刷题时常用容器详解

    当初学java时,只是简单的把java基础知识过了一遍就跑去刷题了,很多知识都是在刷题的过程中慢慢加深理解的. 由于每次刷题时,刷到与容器有关的我基本上都跑去百度了,例如百度一下:java中List的 ...

  8. 理解 Android Binder 机制(一):驱动篇

    Binder的实现是比较复杂的,想要完全弄明白是怎么一回事,并不是一件容易的事情. 这里面牵涉到好几个层次,每一层都有一些模块和机制需要理解.这部分内容预计会分为三篇文章来讲解.本文是第一篇,首先会对 ...

  9. 论文解读《Understanding the Effective Receptive Field in Deep Convolutional Neural Networks》

    感知野的概念尤为重要,对于理解和诊断CNN网络是否工作,其中一个神经元的感知野之外的图像并不会对神经元的值产生影响,所以去确保这个神经元覆盖的所有相关的图像区域是十分重要的:需要对输出图像的单个像素进 ...

  10. 爬虫双色球所有的历史数据并保存到SQLite

    前言 上一篇介绍了双色球走势图是怎么实现的,这一篇介绍怎么实现爬虫所有的双色球历史数据,也可以同步分享怎么同步福彩3D数据.采用的C#来实现的. 同步双色球的地址:https://datachart. ...