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. 多测师_python基本介绍001

    python 一.python的介绍 python 是一门面向对象,解释型,动态类型语言 面向对象:在python中 一切皆为对象 解释型语言:边解释,边执行, 动态类型:就是检查是在运行才做的. 动 ...

  2. golang拾遗:为什么我们需要泛型

    从golang诞生起是否应该添加泛型支持就是一个热度未曾消减的议题.泛型的支持者们认为没有泛型的语言是不完整的,而泛型的反对者们则认为接口足以取代泛型,增加泛型只会徒增语言的复杂度.双方各执己见,争执 ...

  3. Ubuntu20.04 体验和美化

    Ubuntu20.04美化和体验 windows用久了,换下系统也挺好的.ubuntu20.04优化后,用起来蛮舒服的. 系统配置 1.修改软件源 Ubuntu默认是国外的软件源, 我们可以手动切换为 ...

  4. msyql查看连接数

    连接数 SHOW FULL PROCESSLIST 1.  查看允许的最大并发连接数 SHOW VARIABLES LIKE 'max_connections'; 2.  修改最大连接数 方法1:临时 ...

  5. go panic

    panic 抛出异常 通过recover捕获 类似 php python等语言的try catch package mainimport ( "fmt" "errors& ...

  6. FrameworkElementFactory中的SetBinding与SetValue

    public static Microsoft.Windows.Controls.DataGridColumn CreateDateColumn(string path, string header) ...

  7. 一键开启win10全局utf8,编码问题说拜拜

    在windows下开发,开发环境的配置是一个很头大的问题,而编码问题是另一个令人头大的问题,常常出现的中文乱码令人痛不欲生,其原因就在于windows默认的编码并不是现在很普遍的utf8格式,本文就来 ...

  8. Scala 特殊符号含义

    date: 2019-08-01 11:15:27 updated: 2019-08-22 15:22:32 Scala 特殊符号含义 参考地址 1. ::: :::(三个冒号)只用于连接两个 Lis ...

  9. 【5】TensorFlow光速入门-图片分类完整代码

    本文地址:https://www.cnblogs.com/tujia/p/13862364.html 系列文章: [0]TensorFlow光速入门-序 [1]TensorFlow光速入门-tenso ...

  10. 12 Servlet_04 Servlet增删改查 静态页面与动态页面 EL表达式 table表格的一些样式

    今天学习了servlet的增删改查: 存储数据 setAttribute(String name,Object obj );获取数据 getAttribute(String name);删除数据 re ...