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

mysqli - Php Mysqli_fetch_assoc Error : "Warning: Illegal string offset 'name' in" -

html - Cut text on left side inside button while centering -

php - Hide Categories from WordPress Dashboard by ID and Custom Post Type -