typeinfo / typeid输出

编程入门 行业动态 更新时间:2024-10-09 08:35:42
本文介绍了typeinfo / typeid输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正试图调试一段简单的代码,并希望看到一个特定的变量类型在程序中如何改变。

I'm currently trying to debug a piece of simple code and wish to see how a specific variable type changes during the program.

我使用的是typeinfo头文件,所以我可以利用typeid.name()。我知道typeid.name()是编译器特定的,因此输出可能不是特别有帮助或标准。

I'm using the typeinfo header file so I can utilise typeid.name(). I'm aware that typeid.name() is compiler specific thus the output might not be particularly helpful or standard.

我使用 GCC ,但我找不到潜在的输出列表,尽管搜索,假设有一个typeid输出符号的列表。我不想根据输出做任何类型的转换或操作任何类型的数据,只需跟随它的类型。

I'm using GCC but I cannot find a list of the potential output despite searching, assuming a list of typeid output symbols exist. I don't want to do any sort of casting based on the output or manipulate any kind of data, just follow its type.

#include <iostream> #include <typeinfo> int main() { int a = 10; cout << typeid(int).name() << endl; }

有符号列表吗?

推荐答案

我不知道这样的列表是否存在,但是你可以让一个小程序打印出来: p>

I don't know if such a list exists, but you can make a small program to print them out:

#include <iostream> #include <typeinfo> #define PRINT_NAME(x) std::cout << #x << " - " << typeid(x).name() << '\n' int main() { PRINT_NAME(char); PRINT_NAME(signed char); PRINT_NAME(unsigned char); PRINT_NAME(short); PRINT_NAME(unsigned short); PRINT_NAME(int); PRINT_NAME(unsigned int); PRINT_NAME(long); PRINT_NAME(unsigned long); PRINT_NAME(float); PRINT_NAME(double); PRINT_NAME(long double); PRINT_NAME(char*); PRINT_NAME(const char*); //... }

更多推荐

typeinfo / typeid输出

本文发布于:2023-11-15 19:47:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1597430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:typeinfo   typeid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!