• C++如何判断变量类型


    C++如何判断变量类型

    使用 typeid 判断其类型:(需要在编译语言选项中选择 RTTI 编译选项),例子:【引用自这里】,详情可以看这里

    #include <iostream >
    #include <typeinfo.h>
    using namespace std;
    int main()
    {
    	char *p=NULL;
    	char str[]="hello world";
    	cout<<typeid(p).name()<<endl;
    	cout<<typeid(str).name()<<endl;
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    打印出的类型并不是可以直接读懂的,可以参考下面的类型对照表【参考自这里】解读。

      <builtin-type> ::= v	# void
    		 						::= w	# wchar_t
    		 						::= b	# bool
    		 						::= c	# char
    		 						::= a	# signed char
    		 						::= h	# unsigned char
    		 						::= s	# short
    		 						::= t	# unsigned short
    		 						::= i	# int
    		 						::= j	# unsigned int
    		 						::= l	# long
    		 						::= m	# unsigned long
    		 						::= x	# long long, __int64
    		 						::= y	# unsigned long long, __int64
    		 						::= n	# __int128
    		 						::= o	# unsigned __int128
    		 						::= f	# float
    		 						::= d	# double
    		 						::= e	# long double, __float80
    		 						::= g	# __float128
    		 						::= z	# ellipsis
                     				::= Dd # IEEE 754r decimal floating point (64 bits)
                     				::= De # IEEE 754r decimal floating point (128 bits)
                     				::= Df # IEEE 754r decimal floating point (32 bits)
                     				::= Dh # IEEE 754r half-precision floating point (16 bits)
                     				::= DF <number> _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits)
                     				::= DB <number> _        # C23 signed _BitInt(N)
                     				::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
                     				::= DU <number> _        # C23 unsigned _BitInt(N)
                     				::= DU <instantiation-dependent expression> _ # C23 unsigned _BitInt(N)
                     				::= Di # char32_t
                     				::= Ds # char16_t
                     				::= Du # char8_t
                     				::= Da # auto
                     				::= Dc # decltype(auto)
                     				::= Dn # std::nullptr_t (i.e., decltype(nullptr))
    		 						::= u <source-name> [<template-args>] # vendor extended type
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
  • 相关阅读:
    ChatGPT ,AIGC 办公函数案例用5种方法实现区间计算
    LVS+keepalived——高可用集群
    ES6相关语法规范
    FL Studio 20音乐制作教程
    Nginx解析漏洞
    Java基础---第五篇
    如何设置CUDA Kernel中的grid_size和block_size?
    C/C++内存管理
    Flutter 绘制美不胜收的光影流动效果
    【计算机操作系统慕课版】第一章课后习题
  • 原文地址:https://blog.csdn.net/ly869915532/article/details/125525386