C Simple hello world运行,但printf不打印到命令行 #包括 int main() { printf(“Hello World\n”); 返回0; }

C Simple hello world运行,但printf不打印到命令行 #包括 int main() { printf(“Hello World\n”); 返回0; },c,C,这是我的教授给我的简单的hello world程序。这是我在C语言中的第一个程序。我按照指示使用visual studio 2013,我在运行windows 10的Surface Book上。一个同学在完全相同的设置下运行这个程序很好。我的将生成,当我在不调试的情况下运行时,控制台窗口将打开,并且没有文本打印。我无法在线找到解决方案。确保您的程序不会刚刚完成,并快速关闭控制台,使您看不到任何内容。试试这个: #include <stdio.h> int main() { p

这是我的教授给我的简单的hello world程序。这是我在C语言中的第一个程序。我按照指示使用visual studio 2013,我在运行windows 10的Surface Book上。一个同学在完全相同的设置下运行这个程序很好。我的将生成,当我在不调试的情况下运行时,控制台窗口将打开,并且没有文本打印。我无法在线找到解决方案。

确保您的程序不会刚刚完成,并快速关闭控制台,使您看不到任何内容。试试这个:

#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}
#包括
int main()
{
printf(“Hello World\n”);
fflush(stdout);/*确保字符串被输出到std输出*/
getchar();/*等待键完成*/
返回0;
}

已知某些防病毒软件会干扰(如果我没记错的话,我想是Avast)。尝试禁用抗病毒功能,就像测试一样,尝试添加
while(1)之前<代码>返回
。(注意-您必须强制关闭它…)代码非常好。(您也可以在某些联机编译器中尝试。)问题一定是您的设置或尝试执行程序的方式有问题。有时Visual Studio会在您有时间查看打印输出之前关闭窗口。尝试一个
getchar()
返回之前
。我所能说的是,克尼汉和里奇之所以将此作为练习1,是有原因的,而且为什么他们提出在你解决了它(这可能确实是任意困难的!)之后,其他一切都相对容易。
#include <stdio.h>

int main()
{
    printf("Hello World\n");
    fflush (stdout); /* Make sure string is outputted to std output */
    getchar(); /* waits for a key to finish */
    return 0;
}