Logo

Programming-Idioms

History of Idiom 94 > diff from v47 to v48

Edit summary for version 48 by towi:
[C++] elaborate

Version 47

2020-04-29, 11:28:22

Version 48

2020-06-02, 12:40:40

Idiom #94 Print type of variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

Idiom #94 Print type of variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

Variables
x
Imports
#include <typeinfo>
Imports
#include <typeinfo>
Code
std::cout<<typeid(x).name();
Code
std::cout<<typeid(x).name();
Comments bubble
The name of a type is implementation defined and is not neccessarily the same, even between different runs of the program.

Also many implementations allow the availability of type info to be switched off.
Doc URL
https://en.cppreference.com/w/cpp/types/type_info
Demo URL
https://godbolt.org/z/7ZcC6W