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