0
4

1 回答 1

2

From the documentation:

https://www.cplusplus.com/reference/cstring/strncpy/

No null-character is implicitly appended at the end of destination if source is longer than num. Thus, in this case, destination shall not be considered a null terminated C string (reading it as such would overflow).

In general, you need to manually add a '\0' to terminate the string when using strncpy

于 2021-07-24T00:08:08.037 回答