4 ms·
It also makes it possible to have nulls inside a string.
by mehrdadn 6y ago
It also makes it possible to have nulls inside a string.
- saagarjha 6y agoThis is usually a bad idea, FWIW.
- mehrdadn 6y agoI mean, I wasn't trying to suggest you intentionally inject nulls in your strings for no reason! But that doesn't mean your data types should unexpectedly break if this ends up happening...
- saagarjha 6y agoGenerally my policy with std::string and NULs is "don't, ever" because someone is going to call c_str() on it and pass it to a C API, and bad things are going to happen. If you need to embed \0, then use std::vector<char>. Of course, you do get the slight benefit that in the cases where you don't call C APIs you won't have bad things happen, but I wouldn't could on that.
- mehrdadn 6y agoAgain, this isn't about whether you go out of your way to insert it, but about whether the data type should be able to handle it regardless.
- bjoli 6y agoI'll just leave this here: https://youtu.be/5dhSN9aEljg https://youtu.be/5dhSN9aEljg