Ubuntu C++: Convert std::string to const char* using c_str()
In Ubuntu, you can use the c_str() function to convert a std::string to a const char* type.
Here's an example code:
#include <iostream>
#include <string>
int main()
{
std::string str = 'Hello, World!';
const char* cstr = str.c_str();
std::cout << cstr << std::endl;
return 0;
}
This code converts the std::string str to a const char* cstr and then prints it using cout.
原文地址: https://www.cveoy.top/t/topic/pran 著作权归作者所有。请勿转载和采集!