简体   繁体   English

如何在给出额外输入的情况下使控制台输出窗口在Visual Studio 2015中保持打开状态?

[英]How to make the console output window stay open in Visual Studio 2015 stay open when extra input is given?

I wrote the following program in Visual Studio 2015- 我在Visual Studio 2015中编写了以下程序

#include <stdio.h>
#define PRAISE "You are an extraordinary being."
int main(void)
#pragma warning(disable : 4996)
{
    char name[40];

    printf("What's your name? ");
    scanf("%s", name);
    fflush(stdin);
    printf("Hello, %s. %s\n", name, PRAISE);

    getchar();
    getchar();
    getchar();
    getchar();

    return 0;
}

The program runs fine in all cases. 该程序在所有情况下均可正常运行。 But the console window stays open when I provide "Shabbir", "Shabbir K", and "Shabbir Kh" as inputs. 但是,当我提供“ Shabbir”,“ Shabbir K”和“ Shabbir Kh”作为输入时,控制台窗口保持打开状态。 The console window won't stay open if I provide "Shabbir Kha" as input. 如果我提供“ Shabbir Kha”作为输入,则控制台窗口不会保持打开状态。

As you can see, the console window stays open until the second word reaches three character length. 如您所见,控制台窗口保持打开状态,直到第二个单词达到三个字符的长度。 It doesn't stay open if the second word is three or more characters long. 如果第二个单词的长度为三个或更多字符,则它不会保持打开状态。

The same program doesn't show any problems in Code Blocks 13.12. 同一程序在代码块13.12中没有显示任何问题。

to keep the window open: 使窗口保持打开状态:

while( getchar() != EOF );
getchar();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在命令提示符下打开Eclipse控制台输出 - how to open eclipse console output in command prompt 如何在Win32应用中使输出在屏幕上停留一段时间 - How to make the output stay on the screen for a period of time in Win32 app 如何在Linux中打开终端窗口进行调试输出? - How to open terminal window for debug output in Linux? 如何在visual studio .net中快速打开文件 - How to open a file quickly in visual studio .net Visual Studio 2015“窃取”应用程序的控制台 - Visual Studio 2015 “stealing” the application's console Visual Studio Express 2015中的LNK1104错误:无法打开.exe文件 - LNK1104 Error in Visual Studio Express 2015: Cannot open .exe file 如何使用Ansi C打开新的控制台窗口? - how to open new console window using Ansi C? 使用Visual Studio 2015编译时,将控制台(或stdout)重定向到命名管道不再起作用 - Redirecting console (or stdout) to named pipe no longer works when compiling with Visual Studio 2015 尝试在打开的GL中创建空白窗口时出现异常输出 - Unusual output when trying to Create a blank window in open GL 如何使用 Visual Studio 将 Unicode 打印到 C 中的输出控制台? - How do I print Unicode to the output console in C with Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM