title: std::string to char* without cutting bytes
body: <p>So, I'm using a BLE library to receive bytes from a mobile app, and I want to save these bytes in the SD Card of an ESP32 ("Arduino").</p>
  
  <p>The BLE library is receiving the data in this format, as a <code>std::string</code></p>
  
  <pre><code>std::string rxValue = pCharacteristic-&gt;getValue();
  </code></pre>
  
  <p>When I receive the data, I'm doing a <code>Serial.println(rxValue.length())</code> to verify the size of chunks I'm receiving, I'm receiving <strong>512 bytes</strong> as expected, and it's indeed printing <code>512</code></p>
  
  <p>So, it's all good here, I'm receiving the 512 bytes I want, <strong>the problem comes next</strong>:</p>
  
  <p>In order to save to the SD Card, the function that does the writing to the SD card asks me for a <code>char * message</code></p>
  
  <p>So I must convert the <code>std::string</code> into a <code>char *</code>, I'm doing it as follows:</p>
  
  <pre><code>const char *cstr = rxValue.c_str();
  </code></pre>
  
  <p>But whenever I do this, some bytes (that I believe that are bytes out of the alphanumeric/signs spectrum) are cut off, the length is no longer 512 after converting them into a char array, and I need them to be the same 512 bytes to write correctly to the SD card all the bytes.</p>
  
  <p>To test this behavior, I'm printing the length of the <code>char *</code> to see if the 512 bytes are still there:</p>
  
  <pre><code>strlen(cstr)
  </code></pre>
  
  <p>But surprise! <strong>They are not 512 bytes</strong>, they are way less, so I'm doing something wrong when I try to convert the <code>std::string</code> to <code>char *</code></p>
  
  <p>What would be the correct method to transform a chain of bytes that comes in <code>std::string</code> into a <code>char *</code> without loosing bytes :-(</p>
  
  <p>Thank you in advance.</p>