Is it possible to print a variable's type in standard C++?

前端 未结 21 2083
南笙
南笙 2020-11-22 01:41

For example:

int a = 12;
cout << typeof(a) << endl;

Expected output:

int
21条回答
  •  生来不讨喜
    2020-11-22 02:30

    For anyone still visiting, I've recently had the same issue and decided to write a small library based on answers from this post. It provides constexpr type names and type indices und is is tested on Mac, Windows and Ubuntu.

    The library code is here: https://github.com/TheLartians/StaticTypeInfo

提交回复
热议问题