With the magic of user-defined literals, we have yet another solution to this. C++14 added a std::string
literal operator.
using namespace std::string_literals;
auto const x = "\0" "0"s;
Constructs a string of length 2, with a '\0' character (null) followed by a '0' character (the digit zero). I am not sure if it is more or less clear than the initializer_list<char>
constructor approach, but it at least gets rid of the '
and ,
characters.