Currently I have this code in C++ (I'm using Visual Studio 2013):
char * dest= new char[srcLen] {};
strcpy(dest, source);
// ... code using dest ...
delete dest;
How do I convert this to a C++11 unique_ptr using make_unique so that it's usable by strcpy()?
I tried:
auto dest = make_unique<char>(srcLen);
strcpy(dest, source);
However, I'm getting the following compile error on the strcpy line
Error 1 error C2664: 'char *strcpy(char *,const char *)' : cannot convert argument 1 from 'std::unique_ptr<char,std::default_delete<char>>' to 'char *'
Aucun commentaire:
Enregistrer un commentaire