A standard way for getting variable name at compile time
问题 Is there some way in C++11 or higher to achieve a similar behavior to: int some_int; std::string x=variable_name<some_int>::value; //Theoretical code std::cout << x; Result should be: some_int If not, is there a compiler specific way to do it? I am targeting MSVS. 回答1: You ask: Is there some way in C++11 or higher to achieve a similar behavior to: int some_int; std::string x=type_name<some_int>::value; //Theoretical code std::cout << x; Result should be: some_int Yes, you can just use the