আপনি স্ট্রিং বিষয়বস্তু সহ একটি 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