string - C++ memcpy to char* from c_str -


i've done bit of basic reading , i've gathered .c_str() has null terminator.

i have simple c++ program:

int main(int argc, char** argv) {   std::string = "hello";   char to[20];   memcpy(to, from.c_str(), strlen(from.c_str())+1);   std::cout<< << std::endl;   return 0; } 

will memcpy ensure copy on null-terminated string variable (provided string shorter in length)?

memcpy doesn't know string. give range copy. depends on strlen here provide termination point of range


Comments

Popular posts from this blog

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -