C++ content of std::string
来源:互联网 发布:麦包包淘宝商城 编辑:程序博客网 时间:2024/05/18 14:12
sizeof std::string is 4, this is to say it has only a member variable i.e, a pointer to content buffer.
}:cat tt.C
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
void foo(std::string &str)
{
//printf("%s/n",NULL); // To generate a core file
int * p = (int *)&str;
printf("sizeof(std::string) is %d/n",sizeof(str));
printf("*(p+0)=0x%x/n",(*p));
printf("*(*(p+0))='%s'/n",(char *)((*(p+0))));
//printf("*(p+1)=0x%x/n",(*(p+1)));
//printf("*(*(p+1))=%s/n",(char *)((*(p+1))));
}
int main()
{
std::string ss("12345");
foo(ss);
return 0;
}
It will get following output:
}:./a.out
sizeof(std::string) is 4
*(p+0)=0x40e10
*(*(p+0))='12345'
- C++ content of std::string
- C/C++ std::string 切词
- vc++ .net std::string is not a member of std
- C Tips: std::string / std::wstring 的 Trim 函数
- C++/STL std::string 的用法
- C++: std::string 与 Unicode 如何结合?
- [C++]char* const char* std::string区分
- C++:float 转型到 std::string
- C++: std::string 与 Unicode 如何结合?
- std::string 和 c风格字符串
- C++: std::string 与 Unicode 如何结合?
- 【语言-C++】std:string 转换代码
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- Chrome OS能改变未来手机
- 802.11b/g/n速率调节
- SQL 优化经验总结34条
- 字符串处理 11月26
- System.IO.FileSystemWatcher 类
- C++ content of std::string
- C/C++ 文件路径 忽然忘记
- JAVA排序汇总
- Lookup,Countif,Sumif等
- 转的
- 生涯规划
- insert select 和 外部表
- 【转】Linux的图形化桌面管理→目录管理的基础知识
- java 读取文件并显示