Skip to content

Instantly share code, notes, and snippets.

@kuznetsov-m
Created August 16, 2022 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuznetsov-m/6ff02615b6f476afc1bd89010093c899 to your computer and use it in GitHub Desktop.
Save kuznetsov-m/6ff02615b6f476afc1bd89010093c899 to your computer and use it in GitHub Desktop.
print_typename c++ sample
#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