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