0

While running a program in Visual Studio C++ editor, when i click on Local Windows Debugger, the command prompt window opens up, where i am asked to input data (depending on my program). The problem is the window doesn't stay very long after the output is shown.

What do i need to do to keep the window up for a longer time, or at least until i close the window myself?

I tried for over half hour to check various options and see if there is anything that can be done to prolong the duration.

Thanks and regards, Nikhil Kenvetil

Anonymous Person
  • 1,437
  • 8
  • 26
  • 47
  • Are you talking about a console application that closes after it is finished when run from the debugger? Normally you solve that problem by requiring a cin at the end of your main although you can also put a breakpoint there as well. – drescherjm Jun 06 '13 at 14:47
  • Put a 'getchar' at the end ...so it will wait till you enter a character – sethi Jun 06 '13 at 14:48
  • just put a breakpoint at end of main – Balog Pal Jun 06 '13 at 15:06
  • @drescherjm i am taking about the Local Windows Debugger button. I am not sure what the technical term is for this. I am new to C++ :( – Anonymous Person Jun 06 '13 at 15:12
  • @bapusethi, getch hasn't worked. The window just compiles the code, displays the output for a split second and goes off – Anonymous Person Jun 06 '13 at 15:15
  • So, i was watching a tutorial video in YouTube, and when he compiles the prg, it comes with the output window, and has the option "Press any key to continue" on it. I don't get that. sorry to sound very novice, but i am. – Anonymous Person Jun 06 '13 at 15:26
  • http://stackoverflow.com/questions/1775865/visual-studio-console-app-prevent-window-from-closing – drescherjm Jun 06 '13 at 15:38
  • do you want to review my code? i have tried all the things you've asked, but it is simply not working.its driving my MAD! its a simple prg to find the prime numbers between two numbers (range).. – Anonymous Person Jun 06 '13 at 15:39
  • Please post your main() function. Also do you know you could just open a cmd.exe window and cd to to the location of your executable and run it from there by typing its name. – drescherjm Jun 06 '13 at 15:46
  • void main() { int num,i,j,prime; char y; char choice; cout<<"Enter the upper limit :"; cin>>num; cout<<"Prime numbers till "< – Anonymous Person Jun 06 '13 at 16:13
  • sorry, i dunno how to format it here – Anonymous Person Jun 06 '13 at 16:13
  • IT's alright.. i checked http://stackoverflow.com/questions/1775865/visual-studio-console-app-prevent-window-from-closing Exactly what i am looking for!! – Anonymous Person Jun 06 '13 at 16:14
  • BTW, You should have edited your original post and added the source code instead of a comment. Comments are not really good for posting more than a line or 2 of code. – drescherjm Jun 06 '13 at 16:22
  • agreed. thank you very much for all your answers – Anonymous Person Jun 06 '13 at 19:18

3 Answers3

0

Try to use one of the below methods to add some codes at the end of the main() function:

  1. getchar();
  2. char ch; cin>>ch;
Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
James Liu
  • 11
  • 2
0

Try this:

#include <iostream>
#include "conio.h"

int main()
{
    std::cout << "Hello World\n";
    getch();    
    return 0;
}
seccpur
  • 4,996
  • 2
  • 13
  • 21
-1

you could try using system("PAUSE");