std::string does not specifically handle null characters unless you give it an explicit string length. This way your code will work fine.
Although, in C ++ 03, strings are not technically required for storage in continuous memory. Almost every std::string implementation that you find will actually save them that way, but this is not technically necessary. C ++ 11 fixes this.
So, I suggest you use std::vector<char> in this case. std::string will not buy you anything over std::vector<char> , and itβs more explicit that it is an array of characters and not a possible printable string.
source share