Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 0.43 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to put char array into std::string
  2. char* value = new char[required];
  3.         f(name, required, value, NULL); // fill the array
  4.         strResult->assign(value, required);
  5.         delete [] value;
  6.        
  7. std::string strResult(required, '');
  8. f(name, required, &strResult[0], NULL);
  9.  
  10. // optionally, to remove the extraneous trailing NUL (assuming f NUL-terminates):
  11. strResult.pop_back();
  12.  
  13. return strResult;
  14.        
  15. std::string s(charArry);