Created
August 16, 2022 10:50
-
-
Save kuznetsov-m/6ff02615b6f476afc1bd89010093c899 to your computer and use it in GitHub Desktop.
print_typename c++ sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <typeinfo> | |
#if defined __GNUC__ | |
#include <cxxabi.h> // GCC / Clang only | |
#endif | |
#include <string> | |
std::string type_name_to_full_name(const char* name) { | |
char * n = abi::__cxa_demangle(name, 0, 0, 0); | |
std::string s{n}; | |
free(n); | |
return s; | |
} | |
#include <iostream> | |
int main() { | |
{ | |
int i{2}; | |
std::cout << "Typeid name: "<< type_name_to_full_name(typeid(&i).name()) << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment