Answers for "how to check type of a var in c++"

C++
6

how to check datatype of a variable in c++

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

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
Posted by: Guest on August-11-2021

Browse Popular Code Answers by Language