title: Convert char* to string C++
body: <p>I know the starting address of the string(e.g., <code>char* buf</code>) and the max length <code>int l;</code> of the string(i.e., total number of characters is less than or equal to <code>l</code>).</p>
  
  <p>What is the simplest way to get the value of the <code>string</code> from the specified memory segment? In other words, how to implement <code>string retrieveString(char* buf, int l);</code>.</p>
  
  <p><strong>EDIT</strong>: The memory is reserved for writing and reading string of variable length. In other words, <code>int l;</code>indicates the size of the memory and not the length of the string.</p>