解决xcode printf 无输出

来源:互联网 发布:中国城镇住户调查数据 编辑:程序博客网 时间:2024/06/15 03:01

今天用xcode 8.3 的 Command Line Tool 新建了一个c语言程序。官方给出的例子是这样的:

#include <stdio.h>int main(int argc, const char * argv[]) {    // insert code here...    printf("hello,world!\n");    return 0;}

运行起来,console控制台打印良好,没有任何问题。而自己写了一个代码是这样的:

#include <stdio.h>int main(int argc, const char * argv[]) {    // insert code here...    int a = 1;    int b = a++;    printf("b: %d", b);    return 0;}

结果控制台输出是这样的:
这里写图片描述

十分纳闷,goole了很久,并没有找到答案。后来经多次实验发现,在Xcode中想要用printf在控制台打印,需要在末尾加上 \n ,也就是换行符。
希望能帮助遇到同样问题的朋友们。

1 0