logoalt Hacker News

throwaway2037yesterday at 10:15 AM3 repliesview on HN

Doesn't C++'s std::string also use a null terminated char* string internally? Do you count that also?


Replies

zabzonkyesterday at 11:44 AM

Since C++11 it is required to be null-terminated, you can access the terminator with (for e.g.) operator[], and the string can contain non-terminator null characters.

masklinnyesterday at 3:46 PM

It has nul-termination for compatibility with C, so you can call c_str and get a C string. With the caveat that an std::string can have nuls anywhere, which breaks C semantics. But C++ does not use that itself.

anal_reactoryesterday at 10:20 AM

This doesn't count because it's implemented in a way "if you don't need null-terminated string, you won't see it".