How to convert char* to std::string
<p>The following function returns a char*:</p>

<pre><code> // Returns the pointer to the actual packet data.
 // @param pkt_handle The buffer handle.
 // @param queue      The queue from which the packet is arrived or destined.
 // @return           The pointer on success, NULL otherwise.
u_char * pfring_zc_pkt_buff_data(
  pfring_zc_pkt_buff *pkt_handle,
  pfring_zc_queue *queue
);
</code></pre>

<p>and the following function takes a string as input.</p>

<pre><code>  template&lt;class ...Args&gt;
  bool write(Args&amp;&amp;... recordArgs) {
    auto const currentWrite = writeIndex_.load(std::memory_order_relaxed);
    auto nextRecord = currentWrite + 1;
    if (nextRecord == size_) {
      nextRecord = 0;
    }
    if (nextRecord != readIndex_.load(std::memory_order_acquire)) {
      new (&amp;records_[currentWrite]) T(std::forward&lt;Args&gt;(recordArgs)...);
      writeIndex_.store(nextRecord, std::memory_order_release);
      return true;
    }

    // queue is full
    return false;
  }
</code></pre>

<p>I can't change functions code. The <code>u_char * pfring_zc_pkt_buff_data</code> returns a pointer to the actual packet captured by <code>pfring_zc_recv_pkt(zq, &amp;buffers[lru], 1)</code>.</p>

<p>I need to save part of packet to a buffer, So i have to convert u_char* to string*
.there are many similar questions like:</p>

<p><a href="https://stackoverflow.com/questions/1673445/how-to-convert-unsigned-char-to-stdstring-in-c">How to Convert unsigned char* to std::string in C++?</a></p>

<p><a href="https://stackoverflow.com/questions/8126498/how-to-convert-a-const-char-to-stdstring">How to convert a const char * to std::string</a></p>

<p><a href="https://stackoverflow.com/questions/16267578/how-to-convert-char-to-string">How to convert char to string?</a></p>

<p>I couldn't find proper answer for my question.</p>

<p>here are some of my code.</p>

<pre><code>void run() {
    int i=0,n;
    char buf[_snapLengthConnection + _ConnectionHeaderSize];    
    for(;;){
        if(likely(pfring_zc_recv_pkt(zq, &amp;buffers[lru], wait_for_packet)&gt;= 0)) {               
            u_char *pkt_data = pfring_zc_pkt_buff_data(buffers[lru], zq);        
            pfring_print_pkt(buf, sizeof(buf), pkt_data, buffers[lru]-&gt;len,sizeof(buf));       

            std::string *payload;

            //need to save buf to payload
            // how do i copy buf to payload?               
            std::cout&lt;&lt; payload&lt;&lt;"=="&lt;&lt;std::endl;               

            _activeBuffer-&gt;queue-&gt;write(payload);    
        } 
     }

}
</code></pre>

<p>How do i convert u_char* to string?</p>

<p>OS: Ubuntu</p>

<p>gcc version: 4.8.2</p>