how to check datatype of a variable in c++
#include <typeinfo>
...
cout << typeid(variable).name() << endl;
how to check datatype of a variable in c++
#include <typeinfo>
...
cout << typeid(variable).name() << endl;
how to check type 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
}
check variable type c++
if (typeid(variable) == typeid(std::string)) {
std::cout << variable << " is a string" << std::endl;
}
else {
std::cout << variable << " is not a string" << std::endl;
}//you can do this for every type
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us