gpt4 book ai didi

c++ - 在通过 scanf 输入 unsigned char 后,变量周围的堆栈已损坏

转载 作者:太空狗 更新时间:2023-10-29 20:23:53 27 4
gpt4 key购买 nike

#include <stdio.h>
int main()
{
unsigned char y;
scanf("%hhu", &y);
printf("%hhu", y);
return 0;
}

此代码适用于 g++(Dev C++),但会导致 Visual Studio(2010)中的堆栈损坏,这是 VS 错误还是有任何其他方法可以在 VS 中输入 unsigned char 使用 scanf(); ?

最佳答案

听起来 VS 无法处理 %hhu:https://stackoverflow.com/a/15825386/1715829

The important detail is that you're using Windows, and presumably an outdated or non-conforming C environment (compiler and standard library). MSVCRT only supports C89 (and even then, not entirely correctly); in particular, there was no "hh" modifier in C89, and it's probably interpreting "hh" the same as "h" (i.e. short).

关于c++ - 在通过 scanf 输入 unsigned char 后,变量周围的堆栈已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30989608/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com