Is there is a functions that tells you what kind of you data you're dealing with in C++?
In python there exist the type()
function but is there is one in C++?
x = 20
>>> type(x)
<class 'int'>
Is there is a functions that tells you what kind of you data you're dealing with in C++?
In python there exist the type()
function but is there is one in C++?
x = 20
>>> type(x)
<class 'int'>
The most direct equivalent is typeid(var).name()
.
However, in C++ and other static typed languages, this is rarely useful; outside of inheritance and generic programming, any variable can only be a single type, and can't change type.
Note that you have to have #include <typeinfo>
for typeid
to be defined.