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. 2014年 实验二 B2C网上购物

    实验二 B2C网上购物 [实验目的] ⑴.熟悉虚拟银行和网上支付的应用 ⑵.熟悉并掌握消费者B2C网上购物和商家的销售处理 [实验条件] ⑴.个人计算机一台 ⑵.计算机通过局域网形式接入互联网 (3) ...

  2. C&C++代码单元集成测试培训

    课程简介 本课程为期3天,结合实例讲解如何使用Cantata开展C和C++代码,通过培训,可以明显提高工程师操作Cantata的效率,并加速单元测试和集成测试. [日期]2020年11月3日-5日(共 ...

  3. k8s node上查看节点

    node执行 mkdir -p /root/.kube master执行 scp admin.conf node1:/root/.kube/config

  4. es 讲义

    链接: https://pan.baidu.com/s/193jObXs85OZcvAHDycUXlw 提取码: ewbp

  5. subprocess中命令为参数序列和字符串的区别

    参数args 参数args可以是一个参数序列,也可以是一个单独的字符串.参数序列通常是首选的,因为它允许模块处理参数的转义和引号(例如,允许文件名中有空格). 如果传递参数序列,默认情况下,程序执行序 ...

  6. Helium文档8-WebUI自动化-wait_until等待元素出现

    前言 wait_until等待某个条件为真才继续往下执行.默认的超时时间为10s,每0.5查询一次,这俩参数选填.可以设置超时时间和轮询间隔. 可以作为添加后校验元素是否存在的场景 入参介绍 def ...

  7. git折腾日志

    git for windows https://git-for-windows.github.io/ 基本配置 进入git bash后执行 $ git config --global user.nam ...

  8. JavaWeb 图书管理系统

    查看更多系统:系统大全,课程设计.毕业设计,请点击这里查看 01 系统简述 图书管理系统就是利用计算机,结合互联网对图书进行结构化.自动化管理的一种软件,来提高对图书的管理效率. 02 系统特点 集成 ...

  9. 联赛模拟测试22 D. 简单计算

    题目描述 分析 \(\sum_{i=0}^p[(p|qi)?0:1]=\sum_{i=0}^p[(p/gcd(p,q)|qi/gcd(p,q))?0:1]=\sum_{i=0}^p[(p/gcd(p, ...

  10. 硬核!15张图解Redis为什么这么快

    作为一名服务端工程师,工作中你肯定和 Redis 打过交道.Redis 为什么快,这点想必你也知道,至少为了面试也做过准备.很多人知道 Redis 快仅仅因为它是基于内存实现的,对于其它原因倒是模棱两 ...