{"id":101,"date":"2017-08-17T02:20:29","date_gmt":"2017-08-17T02:20:29","guid":{"rendered":"http:\/\/dev.fruitbyte.com\/?p=101"},"modified":"2017-08-20T06:48:54","modified_gmt":"2017-08-20T06:48:54","slug":"how-to-redirect-std-c-streams-to-visual-studio-debug-output","status":"publish","type":"post","link":"http:\/\/dev.fruitbyte.com\/?p=101","title":{"rendered":"How to redirect std C++ streams to Visual Studio debug output"},"content":{"rendered":"<p>Discovered this trick for the first time. You can use\u00a0<code><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/console\/allocconsole\"><span class=\"typ\">AllocConsole<\/span><\/a><span class=\"pun\">()\u00a0to redirect ANY std stream to debug console.<\/span><\/code><\/p>\n<p>In most cases people use either TRACE() statement (but you have include MFC or ATL for that) or Win API <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa363362(v=vs.85).aspx\">OutputDebugString()<\/a>.<\/p>\n<p>With AllocConsole() your code may look like this:<\/p>\n<pre class=\"lang-cpp prettyprint prettyprinted\"><code><span class=\"pln\">\u00a0  freopen<\/span><span class=\"pun\">(<\/span><span class=\"str\">\"CONOUT$\"<\/span><span class=\"pun\">,<\/span> <span class=\"str\">\"w\"<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> stdout<\/span><span class=\"pun\">);\r\n<\/span><\/code><\/pre>\n<p>That&#8217;s\u00a0it!<\/p>\n<p>Learning\u00a0something\u00a0new\u00a0every\u00a0day.\u00a0\ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discovered this trick for the first time. You can use\u00a0AllocConsole()\u00a0to redirect ANY std stream to debug console. In most cases people use either TRACE() statement (but you have include MFC or ATL for that) or Win API OutputDebugString(). With AllocConsole() &hellip; <a href=\"http:\/\/dev.fruitbyte.com\/?p=101\"><em>Continue&nbsp;reading&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/em><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,77,72],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-c","category-lifehack","category-windows"],"_links":{"self":[{"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=101"}],"version-history":[{"count":2,"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":103,"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions\/103"}],"wp:attachment":[{"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.fruitbyte.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}