How to prevent output screen from disappear in Visual Studio 2013 C++ Compiler

后端 未结 10 1916
悲&欢浪女
悲&欢浪女 2020-12-24 08:23

I just downloaded Visual Studio 2013. When I compile C, it doesn\'t show me my output. The output screen will show up for a brief second and then disappears.



        
相关标签:
10条回答
  • 2020-12-24 08:44

    I first used the metioned getchar() and breakpoints solutions but this is no good if you want the program to end (for example if you are using a memory leak detector). I got over this by redirecting the output to a file. You can do this by inserting >output.txt in the command line option under the debug section of project properties

    0 讨论(0)
  • 2020-12-24 08:46

    To keep your screen from closing you can use getchar() as follow in Visual studio:

    #include "stdafx.h"
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    
    int main()
    {
        cout << "Hello\n";
        getchar();
    
    }
    
    0 讨论(0)
  • 2020-12-24 08:51
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
      printf("hello world");
      system("pause"); //this pauses the program until you press any key 
      return 0;
    }
    

    the output will be:

    hello world

    press any key to continue ...

    0 讨论(0)
  • 2020-12-24 08:58

    add this code before return 0 ;

    int  num;
    scanf ("%d",&num);
    

    or

    getchar();
    
    0 讨论(0)
  • 2020-12-24 09:01

    You can also hold CTRL + F5 to get the window to stay open.

    0 讨论(0)
  • 2020-12-24 09:02

    There's several things you can do (I'm assuming you're using Windows):

    1. Compile and execute your program using the Visual Studio Command Prompt program.
    2. Add getchar(); before returning to the OS.
    3. Add system("pause"); before returning to the OS.
    0 讨论(0)
提交回复
热议问题