title: How to convert a std::string which contains '\0' to a char* array?
body: <p>I have a string like, </p>
  
  <pre><code>string str="aaa\0bbb";
  </code></pre>
  
  <p>and I want to copy the value of this string to a char* variable. I tried the following methods but none of them worked.    </p>
  
  <pre><code>char *c=new char[7];
  
  memcpy(c,&amp;str[0],7);    // c="aaa"
  
  memcpy(c,str.data(),7); // c="aaa"
  
  strcpy(c,str.data());   // c="aaa"
  
  str.copy(c,7);          // c="aaa"
  </code></pre>
  
  <p>How can I copy that string to a char* variable without loosing any data?.</p>