You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Code::Blocks发布模式下printf函数异常问题求助

更新于2023年7月25日

感谢各位评论者协助我尝试解决此问题。我仍不确定所遇bug的根源,但最终通过卸载重装Code::Blocks解决了这个麻烦的问题(希望彻底解决)。此外,后续遇到类似问题的用户可先尝试禁用杀毒软件,排查是否因程序被误判为病毒导致无法编译,该方法对我无效,但可能适用于其他人。不过我仍对这个bug感到困惑。

问题求助:Code::Blocks Release模式下的输出异常

在Release模式下,无法输出长度大于7且小于14的字符串,但Debug模式下一切正常。

问题1:特定长度字符串无法输出

例如,尝试输出"Hello World"时无法成功,不符合字符串长度要求:

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   printf("Hello World \n");
}

输出:

Process returned 32766 (0x7FFE)   execution time : 1.581 s
Press any key to continue.

而输出更长的字符串则正常:

#include <stdio.h>
#include <stdlib.h>
int main ()
{

   printf("Hello Worldssss \n");

}

输出:

Hello Worldssss

Process returned 0 (0x0)   execution time : 0.020 s
Press any key to continue.

问题2:短格式字符串无法输出带精度的浮点数

另外,若printf语句中字符不足,无法带精度输出浮点数,且%.2f会被红色下划线标记。

#include <stdio.h>
#include <stdlib.h>
int main ()
{

   float a = 2.34323;

   printf("%.2f", a);

}

输出:

Process returned 32766 (0x7FFE)   execution time : 1.585 s
Press any key to continue.

添加足够字符后则正常:

#include <stdio.h>
#include <stdlib.h>
int main ()
{

   float a = 2.34323;

   printf("This is a test: %.2f", a);

}

输出:

This is a test: 2.34
Process returned 0 (0x0)   execution time : 0.625 s
Press any key to continue.

我完全摸不着头绪,几个月前还能正常运行,从未修改过安装文件或属性,这个问题快把我逼疯了。我知道杀毒软件可能会影响Code::Blocks,但这次似乎并非如此。有人遇到过类似问题吗?

补充信息:当前运行Windows 10系统,使用Code::Blocks 20.03版本。


内容的提问来源于stack exchange,提问作者solace

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 04:25:11