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

java - Last square of 8x8 grid not drawn, using two nested FOR loops -

What design pattern is this code in Javascript? -

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