标签:IV clu return 字符 两种 方法 span print %s
C++中string类,有data(),c_str()两种方法返回const char *类型指针,指向C语言类型的字符串。
注意,一定要用strcpy来操作。
#include <stdio.h> #include <string.h> #include <string> int main() { std::string str = "123abc"; char cstr[20] = ""; strcpy(cstr, str.data()); printf("%s\n", cstr); return 0; }
标签:IV clu return 字符 两种 方法 span print %s
原文地址:https://www.cnblogs.com/tangjicheng/p/9123997.html