Monday, August 2, 2010

difference between strncpy and memcpy

思いっきりはまってしまったので、メモ。 strncpy と memcpy の違い。

strncpy は、src 側の文字列に(途中に) \0 が含まれると、copy をやめてしまう。

また、当たり前だが、const char * を string のコンストラクタに入れると、 \0 まで読み込んで止まってしまうので、サイズも一緒に入れてやるとよい。

[sikaku@localhost compress]$ ./a.out
0 1 2  4 5 6
0 1 2
8
3

No comments:

Post a Comment