Ubuntu系统通过c++如何将string转换为char
在Ubuntu系统中,可以使用c_str()函数将std::string转换为const char*类型。
下面是一个示例代码:
#include <iostream>
#include <string>
int main()
{
std::string str = "Hello, World!";
const char* cstr = str.c_str();
std::cout << cstr << std::endl;
return 0;
}
这段代码将std::string类型的str转换为const char*类型的cstr,然后通过cout打印出来。
原文地址: https://www.cveoy.top/t/topic/hH6l 著作权归作者所有。请勿转载和采集!