Convert std::string to const char*
std::string name = "Anuj";
const char* constName = name.c_str();
Convert std::string to char*
std::string name = "Anuj";
const char* constName = name.c_str();
char *ptrToName = const_cast<char*>(name.c_str());
A simple progam
#include <iostream>
#include <stdio.h>
using namespace
std;
int main()
{
std::string name =
"Anuj";
const char* constName = name.c_str();
char
*ptrToName = const_cast<char*>(name.c_str());
printf("%s",constName);
printf("%s",ptrToName);
cout << name <<
endl;
return 0;
}
Comments
Post a Comment