c++与c
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;
}
随机推荐
- 游戏2048的核心算法c#版本的实现
接触游戏有一段时间了,也写了一些东西,效果还不错,今天没事,我就把2048 c# 版本的实现贴出来,代码已经测试过,可以正常.完美运行.当然了,在网上有很多有关2048的实现方法,但是没有提出到类里面 ...
- k8s集群,使用pvc方式实现数据持久化存储
环境: 系统 华为openEulerOS(CentOS7) k8s版本 1.17.3 master 192.168.1.244 node1 192.168.1.245 介绍: 在Kubernetes中 ...
- MeteoInfoLab脚本示例:站点数据绘制等值线
站点数据绘制等值线需要首先将站点数据插值为格点数据,MeteoInfo中提供了反距离权法(IDW)和cressman两个方法,其中IDW方法可以有插值半径的选项.这里示例读取一个MICAPS第一类数据 ...
- linux centos 03
linux用户权限相关 root用户 相当于qq群的群主 sudo命令 相当于qq群的管理员 普通用户 相当于qq群的 水军 超级用户root的UID是 0 组ID也是 0 普通用户的UID ...
- lumen-ioc容器测试 (2)
lumen-ioc容器测试 (1) lumen-ioc容器测试 (2) lumen-ioc容器测试 (3) lumen-ioc容器测试 (4) lumen-ioc容器测试 (5) lumen-ioc容 ...
- minianaconda3安装
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh chmod +x Miniconda3-lates ...
- 博客主题——cnbook
主题预览 主题下载 gshang.cnbook.rar version:2020-05-29 gshang.cnbook@2.0.rar version:2020-08-25 .source-down ...
- 对于类似经销商的实体中Place(CBM_PALCE_ID = NULL)的情况,如何获取省市信息(限foton)
在库里像上述描述的数据很多,这种情况需要拿fence里的经纬度,反查省市 String[] strArr = data.getFence().getValue().split(";" ...
- 4g工业路由器的覆盖范围分析
4G工业路由器通常覆盖范围在60-80米之间,而影响4G工业路由器的覆盖范围有以下几个因素. 影响4g工业路由器覆盖范围的因素一:环境 空旷的环境下4g工业路由器的信号覆盖范围必然更加广阔,如果传输环 ...
- [Luogu P3338] [ZJOI2014]力 (数论 FFT 卷积)
题面 传送门: 洛咕 BZOJ Solution 写到脑壳疼,我好菜啊 我们来颓柿子吧 \(F_j=\sum_{i<j}\frac{q_i*q_j}{(i-j)^2}-\sum_{i>j} ...