Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <typeinfo>
- using namespace std;
- int main()
- {
- int a = 1996; // An integer variable (a) that holds the value (1996).
- float b = 4.30; // A float variable (b) that holds the value (4.30).
- // Using the typeid function from the <typeinfo> library to get the type of the variable
- // typeid(variable).name returns either i for integer
- // or f for float
- string typeOfA = typeid(a).name();
- string typeOfB = typeid(b).name();
- cout << endl;
- if (typeOfA == "i") cout << "The variable a is an integer number" << endl;
- if (typeOfB == "f") cout << "The variable b is a floating point number (decimal)" << endl;
- cout << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment