C++ string 转char
时间: 2023-08-08 16:09:30 浏览: 94
String和char互转1
可以使用`c_str()`函数将C++中的`string`类型转换为`char`类型的数组。例如:
```cpp
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, world!";
const char* cstr = str.c_str();
std::cout << "str: " << str << std::endl;
std::cout << "cstr: " << cstr << std::endl;
return 0;
}
```
输出:
```
str: Hello, world!
cstr: Hello, world!
```
阅读全文