我目前正试图调试一段简单的代码,并希望看到一个特定的变量类型在程序中如何改变。
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输出
发布评论