문자열 클래스의 c_str() 메서드를 사용하여 문자열 내용이 포함된 const char*를 가져올 수 있습니다.
예시
#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