आप स्ट्रिंग सामग्री के साथ const char* प्राप्त करने के लिए स्ट्रिंग क्लास की c_str() विधि का उपयोग कर सकते हैं।
उदाहरण
#include<iostream>
using namespace std;
int main() {
string x("hello");
const char* ccx = x.c_str();
cout << ccx;
} आउटपुट
यह आउटपुट देगा -
hello
चार* प्राप्त करने के लिए, कॉपी फ़ंक्शन का उपयोग करें।
उदाहरण
#include<iostream>
using namespace std;
int main() {
string x("hello");
// Allocate memory
char* ccx = new char[s.length() + 1];
// Copy contents
std::copy(s.begin(), s.end(), ccx)
cout << ccx;
} आउटपुट
यह आउटपुट देगा -
hello