1

I am using Visual Studio to work on computer code, most times I run pieces of code and they execute successfully but the output flashes on the window so quickly that I don't get to see the output of the code I ran. Is there someway I can see this output or have it stay longer onscreen? I am using C++ on Visual Studio 2013

  • If you create a Console Class than in the Main() Method you have to write Console.ReadLine(); at the end. This example would be for C# – Devid Jun 3 '16 at 11:00
  • Do you mean the output window? Or are you writing a console app? – Dave Jun 3 '16 at 11:01
  • @Dave yes I think I am working on a console app (I am new to this). But my concern is, the command-line interface where my output is supposed to appear, executes the lines of code successfully and disappears so fast I can't know what happened. All I will know is that code executed successfully. – user601099 Jun 3 '16 at 11:11
  • @Devid I guess this won't work for C++ right? I tried to type it and I see that _CONSOLE is the only thing available in library – user601099 Jun 3 '16 at 11:14
1

This is normal for console applications. The console is destroyed when all attached processes end. If you want to keep it open, you need to keep your process running. In C++ you can use

std::string str; std::getline(std::cin, str);

And you'll hit enter to finish the application and let it exit.

  • Thanks so much.. It worked! unfortunately I'm unable to upvote I think (cause I'm new and it's refusing my vote?). Thanks to others who attempted my (initially) poorly written question – user601099 Jun 3 '16 at 14:02
  • while this worked for a certain piece of code I ran it only displays an empty console after running other code, and in some cases does not work. I'll keep in mind what you said about this being normal for console applications but keep question running in case of other solution. – user601099 Jun 3 '16 at 15:31
  • You are making sure to put this line after your relevant code right? What it does is wait for the user to enter any number of characters and hit enter. If you do this before your code, it will wait, get your enter key, run your code and close again. – Richard Robertson Jun 3 '16 at 15:33
  • yes I did try before and after code. I thought after code was most appropriate though – user601099 Jun 3 '16 at 15:36
0

Try to press Ctrl-F5 (Execute without debugger). This way the console window will remain open.

  • I have been using ctrl + f5 for debugging, the windows stays open after successful execution but when I act on the program itself (for example a program which sums integers, if I enter integers and then end the program by entering a non-integer, the "sum" which is the answer, flashes so quickly that I don't get to see the actual answer. For example it sums 163+256+911 and gives correct answer but so quickly that I don't see it before command line window closes) I think my initial question has to be improved upon but this should explain what my problem is – user601099 Jun 3 '16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.