【发布时间】:2017-03-23 08:22:58
【问题描述】:
使用scanf读取指定宽度的整数。
#include <cstdio>
using namespace std;
int main(){
__int16_t a;
__int32_t b;
scanf("%d %d", &a, &b)
return 0;
}
有一个编译器警告说格式说明符“%d”需要 'int *' arg 而不是 '__int16_t *'
那么如何解决呢?
BTW C++11 是不允许的!
【问题讨论】:
-
__int24_t没有格式说明符,因为这不是标准数据类型 - 也许您的编译器对此有一些特殊的扩展(尽管对于整数类型来说它的宽度很奇怪) -
另外你应该更喜欢使用 C++11 fixed-width integer types
-
scanf支持一组有限的数据类型。查看this link 中的format参数说明,熟悉支持的内容。 -
在 C++ 中使用
std::cin代替。它的类型更安全