C ++データ型決意のタイプID

書式#include <iostreamの>

// typeidのテスト


////////////////////////////////////////////////// ////////

メインint型()
{
	{
		int型のV(0);
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		長いV(0);
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		フロートV(0)。
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		ダブルV(0);
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		チャーV(0)。
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		uint8_t V(0)。
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}
	
	{
		uint16_t V(0)。
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		uint32_t V(0)。
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	{
		uint64_tをV(0)。
		std :: coutの<<型ID(V).nameの()<<はstd ::てendl;
		std :: coutの<<型ID(V).raw_name()<<はstd ::てendl;
	}

	0を返します。
}

  

 

 

使用例

書式#include <iostreamの>

// typeidのテスト


////////////////////////////////////////////////// ////////

メインint型()
{
	INT(0);

	//エラーコーリング!
	//比較する2つの文字列が直接使用することはできません==
	//これは、変数の型は、==実行が複数のアドレスである* 2 cosntの文字です。それはfalseを返します!!!!
	もし(typeidを().nameの()== "INT")
	{
		//何かをします
		std :: coutの<< "それは整数である名前で。" <<はstd ::てendl;
	}

	
	[OK]を比較する//使用した文字列
	もし(STD ::文字列(型ID(A).nameの())== "INT")
	{
		//何かをします
		std :: coutのは、<< "それは整数である(のstd ::文字列(型ID().nameの())== \場合。" int型\ ")" <<はstd ::てendl;
	}

	//これは、あまりにも、同じオブジェクト、自然のアドレス文字列を返すことができます。
	オートP1 =タイプID().nameの()。
	自動P2 =タイプID(1).nameの()。
	もし(typeidを()==型ID(1))//比較
	{
		//何かをします
		std :: COUT << "それが整数である場合(タイプID()==型ID(1))。" <<はstd :: ENDL。
	}

	もし(型ID(A)==型ID(1.0F))//比較
	{
		//何かをします
		std :: coutの<< "それが整数である場合(型ID()==型ID(1.0F))。" <<はstd ::てendl;
	}

	もし(typeidを()==型ID(INT(1.0)))//比較
	{
		//何かをします
		std :: coutの<< "それが整数である場合(型ID()==型ID(INT(1.0)))" <<はstd ::てendl;
	}

	0を返します。
}

  

 

おすすめ

転載: www.cnblogs.com/alexYuin/p/11966101.html