相关疑难解决方法(0)

解开std :: type_info :: name的结果

我目前正在研究一些日志代码,它们应该 - 除其他外 - 打印有关调用函数的信息.这应该相对容易,标准C++有一个type_info类.它包含typeid'd类/函数/ etc的名称.但它被破坏了.它不是很有用.即typeid(std::vector<int>).name()回归St6vectorIiSaIiEE.

有没有办法从中产生有用的东西?就像std::vector<int>上面的例子一样.如果它只适用于非模板类,那也没关系.

该解决方案应该适用于gcc,但如果我可以移植它会更好.这是为了记录所以它不是那么重要,它不能被关闭,但它应该有助于调试.

c++ gcc name-mangling

85
推荐指数
6
解决办法
4万
查看次数

在C中确定运行期间变量的类型

我有几个char(array),int和double类型的变量.有没有办法确定它们在运行时的类型?

例如,我正在寻找类似的东西:

int dummyInt = 5;    
double dummyDouble = 5.0;    
dummyInt == int ?
        printf("yes, it's of int type\n") : printf("no, it's not of int type\n");
dummyDouble == int ?
        printf("yes, it's of int type\n") : printf("no, it's not of int type\n");
Run Code Online (Sandbox Code Playgroud)

显而易见的结果将是:

是的,它是int类型
否,它不是int类型

好吧,我需要它的原因是因为我将数据从变量传输到SQL数据库(使用SQLite).现在,每次运行程序时标头都会改变,具体取决于使用的变量.因此,当我创建表时,我需要告诉它是否为VARCHAR,INTEGER,DOUBLE等.

c types runtime

1
推荐指数
1
解决办法
1635
查看次数

标签 统计

c ×1

c++ ×1

gcc ×1

name-mangling ×1

runtime ×1

types ×1