<p>I created a C++ console app and just want to capture the cout/cerr statements in the Output Window within the Visual Studio 2005 IDE. I'm sure this is just a setting that I'm missing. Can anyone point me in the right direction?</p>

[{'answer_id': 73363, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 3, 'selected': False, 'text': '<p>You can\'t do this.</p>\n\n<p>If you want to output to the debugger\'s output window, call OutputDebugString.</p>\n\n<p>I found <a href="http://www.flipcode.com/archives/Message_Box_ostream.shtml" rel="noreferrer">this implementation</a> of a \'teestream\' which allows one output to go to multiple streams. You could implement a stream that sends data to OutputDebugString.</p>\n'}, {'answer_id': 73365, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Is this a case of the output screen just flashing and then dissapearing? if so you can keep it open by using cin as your last statement before return.</p>\n'}, {'answer_id': 74542, 'author': 'ben', 'author_id': 4607, 'author_profile': 'https://Stackoverflow.com/users/4607', 'pm_score': 3, 'selected': False, 'text': '<p>You can capture the output of cout like this, for example:</p>\n\n<pre><code>std::streambuf* old_rdbuf = std::cout.rdbuf();\nstd::stringbuf new_rdbuf;\n// replace default output buffer with string buffer\nstd::cout.rdbuf(&amp;new_rdbuf);\n\n// write to new buffer, make sure to flush at the end\nstd::cout &lt;&lt; "hello, world" &lt;&lt; std::endl;\n\nstd::string s(new_rdbuf.str());\n// restore the default buffer before destroying the new one\nstd::cout.rdbuf(old_rdbuf);\n\n// show that the data actually went somewhere\nstd::cout &lt;&lt; s.size() &lt;&lt; ": " &lt;&lt; s;\n</code></pre>\n\n<p>Magicking it into the Visual Studio 2005 output window is left as an exercise to a Visual Studio 2005 plugin developer. But you could probably redirect it elsewhere, like a file or a custom window, perhaps by writing a custom streambuf class (see also boost.iostream).</p>\n'}, {'answer_id': 78699, 'author': 'Adam Mitz', 'author_id': 2574, 'author_profile': 'https://Stackoverflow.com/users/2574', 'pm_score': 2, 'selected': False, 'text': "<p>A combination of ben's answer and Mike Dimmick's: you would be implementing a stream_buf_ that ends up calling OutputDebugString.  Maybe someone has done this already?  Take a look at the two proposed Boost logging libraries.</p>\n"}, {'answer_id': 80782, 'author': 'el2iot2', 'author_id': 8668, 'author_profile': 'https://Stackoverflow.com/users/8668', 'pm_score': 0, 'selected': False, 'text': '<p>Also, depending on your intentions, and what libraries you are using, you may want to use the <a href="http://msdn.microsoft.com/en-us/library/4wyz8787(VS.80).aspx" rel="nofollow noreferrer">TRACE macro</a> (<a href="http://en.wikipedia.org/wiki/Microsoft_Foundation_Class_Library" rel="nofollow noreferrer">MFC</a>) or <a href="http://msdn.microsoft.com/en-us/library/6xkxyz08(VS.80).aspx" rel="nofollow noreferrer">ATLTRACE</a> (<a href="http://en.wikipedia.org/wiki/Active_Template_Library" rel="nofollow noreferrer">ATL</a>).</p>\n'}, {'answer_id': 6086817, 'author': 'Yakov Galka', 'author_id': 277176, 'author_profile': 'https://Stackoverflow.com/users/277176', 'pm_score': 4, 'selected': False, 'text': '<p>I\'ve finally implemented this, so I want to share it with you:</p>\n\n<pre><code>#include &lt;vector&gt;\n#include &lt;iostream&gt;\n#include &lt;windows.h&gt;\n#include &lt;boost/iostreams/stream.hpp&gt;\n#include &lt;boost/iostreams/tee.hpp&gt;\n\nusing namespace std;\nnamespace io = boost::iostreams;\n\nstruct DebugSink\n{\n    typedef char char_type;\n    typedef io::sink_tag category;\n\n    std::vector&lt;char&gt; _vec;\n\n    std::streamsize write(const char *s, std::streamsize n)\n    {\n        _vec.assign(s, s+n);\n        _vec.push_back(0); // we must null-terminate for WINAPI\n        OutputDebugStringA(&amp;_vec[0]);\n        return n;\n    }\n};\n\nint main()\n{\n    typedef io::tee_device&lt;DebugSink, std::streambuf&gt; TeeDevice;\n    TeeDevice device(DebugSink(), *cout.rdbuf());\n    io::stream_buffer&lt;TeeDevice&gt; buf(device);\n    cout.rdbuf(&amp;buf);\n\n    cout &lt;&lt; "hello world!\\n";\n    cout.flush(); // you may need to flush in some circumstances\n}\n</code></pre>\n\n<p><strong>BONUS TIP:</strong> If you write:</p>\n\n<pre><code>X:\\full\\file\\name.txt(10) : message\n</code></pre>\n\n<p>to the output window and then double-click on it, then Visual Studio will jump to the given file, line 10, and display the \'message\' in status bar. It\'s <em>very</em> useful.</p>\n'}, {'answer_id': 57573500, 'author': 'ejectamenta', 'author_id': 1740850, 'author_profile': 'https://Stackoverflow.com/users/1740850', 'pm_score': 0, 'selected': False, 'text': '<p>Write to a std::ostringsteam and then TRACE that.</p>\n\n<pre><code>std::ostringstream oss;\n\noss &lt;&lt; "w:=" &lt;&lt; w &lt;&lt; " u=" &lt;&lt; u &lt;&lt; " vt=" &lt;&lt; vt &lt;&lt; endl;\n\nTRACE(oss.str().data());\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/73286', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1265473/']