鱼C论坛

 找回密码
 立即注册

C++typeid显示可读性

热度 3已有 700 次阅读2016-3-8 07:43 |个人分类:C++

#include <iostream>
#include<cstring>
#include <typeinfo>
using namespace std;
int main()
{
    int a = 10;
    double *p;
    wchar_t *pstr;

    cout << typeid(a).name() << endl;
    cout << typeid(p).name() << endl;
    cout << typeid(pstr).name() << endl;
    cout << typeid( typeid(p).name()).name() << endl;
    int *px;
    int *py;
    if (strcmp(typeid(px).name(),typeid(py).name())==0)
    {
        cout << "相等";
    } 
    else
    {
        cout << "bu相等";
    }

    return 0;
}  

xin@xin-virtual-machine:~/c++/template$ ./all
i
Pd
Pw
PKc
相等xin@xin-virtual-machine:~/c++/template$ c++filt -t Pd
double*
xin@xin-virtual-machine:~/c++/template$ c++filt -t Pw
wchar_t*
xin@xin-virtual-machine:~/c++/template$ c++filt -t PKc
char const*

P表示指针类型
K表示常量
w wchar_t
c char
d double



路过

鸡蛋
2

鲜花

握手

雷人

刚表态过的朋友 (2 人)

全部作者的其他最新日志

发表评论 评论 (1 个评论)

回复 pl_014 2017-2-16 20:45
用的是什么编译器?msvc2013显示的是类型全称,mingw也没见过这样的缩写。

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 18:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部