How to check whether a given number is integer or float type in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to check whether a given number is integer or float type in C++?

27th Jul 2018, 7:41 AM
Nikash
Nikash - avatar
3 Answers
+ 3
Include typeinfo library and use typeid().name() #include <typeinfo> ... cout << typeid([variable]).name() << endl;
27th Jul 2018, 7:46 AM
apex137
apex137 - avatar
+ 2
#include <typeinfo> ... cout << typeid(variable).name() << endl;
27th Jul 2018, 8:15 AM
Negar Kamranian
+ 2
You could use modf from math library to extract decimal part and check if it is zero. Example: https://code.sololearn.com/c29OHjXbSokC/?ref=app
18th Dec 2018, 4:07 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar