Check whether a variable is a numeric or string

2

Good afternoon, Is there a function in C ++ that checks whether the variable is a string or numeric?

An example: In PHP I use is_string (variable) or is_numeric (variable).

    
asked by anonymous 24.08.2015 / 22:34

1 answer

2

If you are using GCC you can use typeof. It returns a string with the type of the variable. Ex.:

#include <iostream>

std::cout << typeof(int&) << '\n'; // int

You can also use the type ID. So:

#include <typeinfo>

// …
std::cout << typeid(a).name() << '\n';

Have this question here in Stackoverflow in English that explains the difference between the 2 .

    
24.08.2015 / 22:40