Comment by jchw

2 years ago

You only have to care about it at boundaries though, for the most part. Like, when calling a C API. That's easy to handle. Even C++'s std::string can do that, as the c_str method always returns a null-terminated string. That inherently kills the need for things like strcat.

The return from c_str cannot be used everywhere you would normally use a null terminated string, because the return is const.

For example, you couldn't pass it to strtok, or any other function that needs to even temporarily modify the string.

  • strtok is an abomination. The only reason it needs to modify the input string in the first place is to support zero-terminated output strings without having to make copies.

  • While this is true, passing a string to a C function that is manipulating the string would defeat the point of not using C string manipulation.