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

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

For example:

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

Expected output:

int
21条回答
  •  太阳男子
    2020-11-22 02:09

    Don't forget to include

    I believe what you are referring to is runtime type identification. You can achieve the above by doing .

    #include 
    #include 
    
    using namespace std;
    
    int main() {
      int i;
      cout << typeid(i).name();
      return 0;
    }
    

提交回复
热议问题