How can I print the exact type of variables in c++?

133 Views Asked by At

What I know:

#include <iostream>
#include <typeinfo>
using namespace std;

int main()  
{    
    int a = 3;
    const int& b = 4;
    cout<<typeid(a).name()<<endl;
    cout<<typeid(b).name()<<endl;
}

So this will going to print:

i    // i stands for int
i    

But my question is what can I do to print the exact type of b?

This is what I tried :

#include <iostream>
#include <typeinfo>
using namespace std;

int main()  
{    
    int a = 3;
    const int& b = 4;
    cout<<typeid(a).name()<<endl;
    cout<<typeid(b).name()<<endl;
    
    decltype(b) k = 4;
    cout<<typeid(k).name()<<endl;
    return 0;
}

but still, the output is :

i
i
I

I mean isn't there any function for efficiently getting the type of variable...

0

There are 0 best solutions below