5

Most IDE's I've seen (NetBeans, QtCreator, XCode, CodeBlocks, Eclipse) provide an out-of-the-box method to view standard output either in one of its embedded window or external console or in a log BUT Visual Studio.

I really don't want to allocate a separate console as it is suggested at THIS question. I'd also prefer not to redirect it to a file as it is suggested at THIS question (output file is not created with the suggested console command (2>output.txt)). Please don't give answers that modify the codebase like using OutputDebugString.

If displaying standard output inside VS this way is not possible, a working solution of the other two alternatives would still be welcomed, namely using external console (which I tried using without seeing the output in it) or a log file.

Community
  • 1
  • 1
MatrixAndrew
  • 265
  • 3
  • 13
  • Modify which codebase please what? Clarify your question please! – πάντα ῥεῖ Jan 13 '16 at 19:03
  • Without modifying any part of the source code, simply. – MatrixAndrew Jan 13 '16 at 19:04
  • Which source code? Did you show any in your question? (Note that links don't count) – πάντα ῥεῖ Jan 13 '16 at 19:05
  • Why do I have to show source code if I'd want to avoid modifying any source code whatsoever? (this includes .h, .cpp files) – MatrixAndrew Jan 13 '16 at 19:07
  • 5
    It's not the IDE, it's the way Windows programs work. By default there is either a console or a graphics window, not both. – Bo Persson Jan 13 '16 at 19:08
  • @πάντα-ῥεῖ - He's got a program he wants to run under Visual Studio. He wants to see stdout. You don't need to see the code for the program. – Martin Bonner supports Monica Jan 13 '16 at 19:09
  • I would say if you do not want to allocate a console for a GUI application or change the code or use /SUBSYSTEM:CONSOLE you are out of luck. – drescherjm Jan 13 '16 at 19:09
  • I'd want to use /SUBSYSTEM:CONSOLE, I tried too (this I aliased as "external console" in my question), without success. If you could point me in the direction how to make this work with that method I'd be very thankful. – MatrixAndrew Jan 13 '16 at 19:10
  • 1
    @MatrixAndrew To be clear: Do you have a program which starts at `main` or at `WinMain`? If the former, I get stdout displayed in a separate console; if the latter, Windows (not Visual Studio) typically sends stdout to a black hole. – Martin Bonner supports Monica Jan 13 '16 at 19:11
  • entry point looks like this: http://pastebin.com/6WyHcAKc – MatrixAndrew Jan 13 '16 at 19:13
  • 1
    Did you try the editbin method in my answer: http://stackoverflow.com/a/13841522/487892 – drescherjm Jan 13 '16 at 19:14
  • 2
    Then that is your problem. Windows is sending your stdout to a black hole. If you want a graphics window and a console, you will have to change the code to create a console. – Martin Bonner supports Monica Jan 13 '16 at 19:16
  • 1
    @drescherjm As a last resort I may try to use that method, but I'm still in shock due to the realization why one would need to do something like this manually when all other IDE's provide this functionality out-of-the-box. – MatrixAndrew Jan 13 '16 at 19:18
  • Like others mentioned you are fighting windows on that. It's not really the IDE that is the problem. – drescherjm Jan 13 '16 at 19:20
  • Also I was hoping with VS2015 something has changed that enables what I'd seek. I'm fighting with a Windows on a lot of fronts, I recently spent half a day debugging environment variables because the existence of whitespaces after semicolons screws up the entire parsing of the variable paths. – MatrixAndrew Jan 13 '16 at 19:20
  • Simple answer is VS2015 does not have this feature. – drescherjm Jan 13 '16 at 19:21
  • @MatrixAndrew With those other IDE's other than VS, what if a developer does *not* want the IDE to do these things, because possibly the developer is writing code that allocates a console window? That would be confusing as heck... – PaulMcKenzie Jan 13 '16 at 19:22
  • Thank you for responses then, I'll probably go with the method that works with the previous versions as well then, allocating a console. I'd appreciate if you'd balance the score of my question to at least 0, because it is a legitimate question and I get prolonging existential crisis when I get downvotes. – MatrixAndrew Jan 13 '16 at 19:25
  • @drescherjm In your answer a macro "_O_TEXT" is used, it is not defined in the MSVC library like the rest and neither can I find anything about it on the net. Have they removed this recently? Is there an alternative way? – MatrixAndrew Jan 14 '16 at 13:37
  • 1
    The documentation for _open_osfhandle describes these parameters: https://msdn.microsoft.com/en-us/library/bdts1c9x.aspx – drescherjm Jan 14 '16 at 13:52
  • had to be included too, all compiles and I get the console but so far cout and cerr does not output into it w/wo debugger (I use your openConsole() method as global function) I'll keep trying – MatrixAndrew Jan 14 '16 at 14:04
  • No success. So only way left is if I convert this into a non-win32 application by creating a regular int main() entry point, too bad it's probably not possible with this project, well.. – MatrixAndrew Jan 14 '16 at 14:30

1 Answers1

1

If it is only for debugging purposes, you might find Debug Breakpoints/Tracepoint actions helpful. They enable to log custom strings with expressions (i.e. variables) to the visual studio console.

For a non-console windows application, by default (i.e. without changing your codebase, as you are requesting) all output to stdout is lost..

Jack White
  • 409
  • 4
  • 11