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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

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

ios - I get the error Property '...' not found on object of type '...' -