项目场景:
在stm32项目中为了调试将某些参数打出来,重定向printf
问题描述
printf打印不出东西

缓冲区满了才打印出来

原因分析:
使用printf函数必须等到缓冲区满或程序结束时,才进行写入到屏幕
解决方案:
解决方法一:加 \n 回车

解决方法二: 加 fflush(stdout); 刷新输出流将缓冲区中的数据立即写入到文件(或显示设备)中,而不是等到缓冲区满或程序结束时才进行写入。

解决方法三: 在初始化中加入 setvbuf(stdout, NULL, _IONBF, 0); 将缓冲区置为0
