TreeviewCopyright © aleen42 all right reserved, powered by aleen42

conversion between string, char*, const char* Back

string

  • to char*
string s = "abc";

/* new a char pointer and point to a char instance with the size */
char* c;
const int len = s.length();
c = new char[len + 1];

/* use strcpy to copy string to the char instance */
strcpy(c, s.c_str());
  • to const char*
string s= "abc";

const char* c_s = s.c_str();

const char*

  • to char*
char* c;
const char* c_s = "abc";

const int len = strlen(c_s) + 1;
strcpy(c, c_s);
  • to string
const char* c_s = "abc";
string s(c_s);

char*

  • to const char*
const char* c_s = "abc";
char* c = c_s
  • to string
char* c = "abc";
string s(c);
Empty Comments
Sign in GitHub

As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.

Notice: This plugin has used Cookie to store your token with an expiration.