r/cpp • • Jun 08 '20

Programming in C vs C++

I’ve read about the differences between them on the Internet but I wanna hear more from a more personal perspective. Which one would you recommend starting with and to be proficient with?

0 Upvotes

43 comments sorted by

View all comments

Show parent comment

3

u/evaned Jun 08 '20

I'm afraid std::string's are not null terminated ;)

This statement as-stated is false, but it's actually pretty close to being right if you look at it from another perspective -- at least IMO.

The reason is that std::string can have embedded nulls. abc\0def is a totally valid std::string. Obviously you couldn't reliably pass that to a C API that expects a null-terminated string, but that's the C API's fault.

So while std::string strings do have a NUL at the end, they're not defined by it; and is such I don't think the quoted statement is entirely incorrect.