在 Xcode 8.3 更新中,C/C++ 编程 printf 不给出没有换行符的输出 [英] In Xcode 8.3 update, C/C++ programming printf does not give output without newline

查看:33
本文介绍了在 Xcode 8.3 更新中,C/C++ 编程 printf 不给出没有换行符的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上周更新到 Xcode 8.3 后,在 C/C++ 程序中,printf 语句的输出不再出现在屏幕上,没有换行符.因此,我无法提示用户输入一个数字,并让他们在输入提示后的同一行中输入该数字.

After last week's updated to Xcode 8.3, in a C/C++ program the output from a printf statement no longer appears on the screen without a newline. Thus I can't prompt for the user to enter a number, and have them type in that number on the same line following the input prompt.

既不刷新输出缓冲区 [fflush(stdout)cout <<endl] 或将输出缓冲区设置为 NULL [setbuf(stdout, NULL)] 解决了这个问题,而是一个专门关于 Xcode 8.3 似乎被破坏的问题.

Neither flushing the output buffer [fflush(stdout) or cout << endl] nor setting the output buffer to NULL [setbuf(stdout, NULL)] addresses this problem, but rather is a question specifically about Xcode 8.3 seemingly being broken.

scanf注释掉,下面程序的输出是:

With the scanf commented out, the output of the program below is:

Enter a value for x: Value of x is: 0

使用 scanf 后,第一个 printf 的输出永远不会出现.如果您继续输入一个值并按回车键,它只会显示然后.输出为:

With the scanf in place, the output from the first printf never shows up. If you go ahead and type in a value and press enter, only then does it show up. Output is:

3
Enter a value for x: Value of x is: 3

完整的测试程序在这里:

Full test program is here:

#include <iostream>
using namespace std;

int main() {
    int x=0;
    printf("Enter a value for x: ");
    //scanf("%d", &x);

    printf("Value of x is: %d\n", x);
    return 0;
}

我的解决方法是恢复到 Xcode 8.2.1,从 developer.apple.com/xcode/downloads/下载

My work-around has been to revert back to Xcode 8.2.1, downloaded from developer.apple.com/xcode/downloads/

推荐答案

8.3.2 于昨晚宣布并解决了这个问题:

8.3.2 was announced last night and addresses this supposedly:

这篇关于在 Xcode 8.3 更新中,C/C++ 编程 printf 不给出没有换行符的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆