@GeruzoniAnsasu c++2a 可以使用字符串模版
template<size_t N> struct StringLiteral { constexpr StringLiteral(const char (&str)[N]) { std::copy_n(str, N, value); } char value[N]; }; template<StringLiteral lit> void Print() { // The size of the string is available as a constant expression. constexpr auto size = sizeof(lit.value); // and so is the string's content. constexpr auto cOntents= lit.value; std::cout << "Size: " << size << ", Contents: " << contents << std::endl; } int main(int argc, const char * argv[]) { Print<"litral string">(); // Prints "Size: 15, Contents: literal string" return 0; }