C++ – Assigning null to a std::string

I can’t assign a null to a String?

No. std::string is not a pointer type; it cannot be made “null.” It cannot represent the absence of a value, which is what a null pointer is used to represent.

It can be made empty, by assigning an empty string to it (s = "" or s = std::string()) or by clearing it (s.clear()).

Leave a Comment