How to compare variables type in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

int main()
{
	int i, j;
	double d;

	if (typeid(i) == typeid(j))
		cout << "types i and j are the same" << endl;
	if (typeid(i) != typeid(d))
		cout << "types i and d are not the same" << endl;
	
	return 0;
}


/*
run:

types i and j are the same
types i and d are not the same

*/

 



answered Jun 5, 2018 by avibootz

Related questions

1 answer 227 views
1 answer 195 views
1 answer 133 views
1 answer 141 views
1 answer 235 views
...