Reputation:
I'm practising writing recursive functions using Visual Studio 2015 on Windows 7.
I use cout
to track the progress of my code, but it shows too many results and even though I stop the program I can not see the initial result... I can only see the output from the middle.
How can I see the complete program output?
Upvotes: 0
Views: 397
Reputation: 5352
The problem is that cmd.exe
(the Windows commad prompt) has a fixed-size buffer for displaying output. If your program writes a lot of output, only the last N lines will be displayed, where N is the buffer size.
You can avoid this problem in several ways:
Write to a file, instead of to std::cout
. All of your output will be captured in the file, which you can read in the text editor of your choice.
Redirect the standard output to a file. Run your program as my_prog.exe > output.log
and the output will be redirected to output.log
.
Pipe your output to the more
command, to show it one screen at a time: my_prog.exe | more
Increase the cmd.exe
buffer size. If you right-click on the title bar of the command window, you can select the Properties menu option. Within the Layout tab, you'll see a section called Screen buffer size. Change the Height to a larger value, and you'll be able to capture that many lines of output. Note that this is somewhat unreliable, since you often don't know in advance of executing your program how many lines it will output. One of the other approaches, using files, is often a better solution.
Note that this isn't really a problem with your C++ program. It's entirely reasonable to be able to produce a large quantity of output on the standard output stream. The best solutions are the ones that redirect or pipe the output to a file. These operations are available on most sensible platforms (and Windows, too) and do exactly what you need without having to change your program to write to a file.
Upvotes: 1
Reputation: 5599
Run your application from the commandline and redirect the output to a file:
yourapp.exe > yourapp.log
Upvotes: 0
Reputation: 185
I'm not sure to understand your problem, maybe you should write the output in a file instead of the standard output ? Then you will see all your results
Upvotes: 0