1.const char* p: p is a pointer to const char(char const* p 一样) 意思就是不能通过p指针来修改p指向的内容(但是内容可以修改). 2.char* p : p is a pointer to char 意思就是可通过p指针来修改p指向的内容 3.char* const p: p is a const pointer to char 意思就是p指针是一个常指针,他指向的内存地址不能变,定义的时候就得初始化 一旦给…
std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 version doesn't work for buf NULL/size 0, so try printing // into a small buffer that avoids the double-rendering and alloca path too... char short_b…
How to convert a std::string to const char* or char*? 1. If you just want to pass a std::string to a function that needs const char* you can use std::string str; const char * c = str.c_str(); If you want to get a writable copy, like char *, you can d…
1.字符串 字符串本质就是一串字符,在C++中大家想到字符串往往第一反应是std::string(后面简称string) 字符串得从C语言说起,string其实是个类,C语言是没有class的,所以C语言的字符串其实就是字符数组,也就是char [ ] ,例如: char str[10]; //定义了一个有十个元素的数组,元素类型为字符char char str[10] = {"hello"}; //"h e l l o \0"五个字符赋给str数组, 然…