title: How to convert a string to unsigned char array in c++
body: <pre><code>string temp;
  temp = line.substr(0, pos);
  </code></pre>
  
  <p>I need to convert the string temp to an unsigned char array. Could someone please tell me how this can be done? I tried the methods mentioned in the below link but they didn't work.</p>
  
  <p><a href="https://stackoverflow.com/questions/2206050/how-to-convert-a-string-literal-to-unsigned-char-in-visual-c">How to convert a string literal to unsigned char array in visual c++</a></p>
  
  <pre><code>unsigned char* val=new[temp.size() + 1](); //Error: Expected a type.
  copy(temp.begin(), temp.end(), val);
  </code></pre>