Answers for "how to check the datatype of a variable in c++"

C++
4

how to check datatype of a variable in c++

#include <typeinfo>
...
cout << typeid(variable).name() << endl;
Posted by: Guest on May-29-2020
2

how to check the datatype of a variable in c++

#include <typeinfo>
#include <iostream>

class someClass { };

int main(int argc, char* argv[]) {
    int a;
    someClass b;
    std::cout<<"a is of type: "<<typeid(a).name()<<std::endl; 
  	// Output 'a is of type int'
    std::cout<<"b is of type: "<<typeid(b).name()<<std::endl; 
  	// Output 'b is of type someClass'
    return 0;
  	// on the online compiler it comes as 'i' for int and 'c' for char
}
Posted by: Guest on May-02-2020
0

how to know datatype of something in c++

int k;
cout << typeid(k).name() << endl;
Posted by: Guest on January-10-2021

Code answers related to "how to check the datatype of a variable in c++"

Browse Popular Code Answers by Language