可以将std :: cout重定向到Visual Studio 2010 C ++开箱即用的输出视图吗?

时间:2011-12-13 02:08:50

标签: visual-studio-2010

我想知道是否可以在最新版本的VS中通过一个简单的设置来完成,这个设置导致VS的行为方式与Eclipse IDE中的“ContextMenu”>运行“a_Java_src_file_with_main”相同。我在新的W7平台上使用VS 2010 Pro的试用版。即使是添加到“空”模板生成的项目中的最小helloworld cpp源文件也会重定向到命令窗口。

同样的问题3年前:
Capturing cout in Visual Studio 2005 output window?
和9个月前:
How to redirect stdout to output window from visual studio

我知道使用OutputDebugString(...)并将流重定向到文件作为替代。
Capture console output for debugging in VS?

1 个答案:

答案 0 :(得分:0)

执行此操作的简单方法是通过使用suppress the console window构建可执行文件来实现“ WinMain entry point on windows instead of main”。

通常可以通过编辑项目设置来完成,但是,如果像我一样使用Public Sub DataToSummary() Dim wbk As Workbook Dim Filename As String Dim Path As String Dim LastRowMaster As Long Dim DataRowsMaster As Long Dim LastRowSource As Long Dim FileNameSource As String Dim i As Integer, intValueToFind As Integer Path = "C:\Example\Path\" Filename = Dir(Path & "*.xlsx") Do While Len(Filename) > 0 Set wbk = Workbooks.Open(Path & Filename) For i = 1 To 500 If Cells(i, 1).Value = intValueToFind Then GoTo Skip End If Next i LastRowSource = Cells(Rows.Count, 2).End(xlUp).Row DataRowsSource = LastRowSource - 6 FileNameSource = Left(Filename, Len(Filename) - 5) Workbooks(Filename).Sheets(1).Range("B7:M" & LastRowSource).Copy Workbooks("Master.xlsb").Activate LastRowMaster = Cells(Rows.Count, 6).End(xlUp).Row ThisWorkbook.Sheets(1).Range("F" & LastRowMaster + 1).PasteSpecial xlPasteValues ThisWorkbook.Sheets(1).Range("B" & LastRowMaster + 1 & ":B" & LastRowMaster + DataRowsSource).Value = FileNameSource ThisWorkbook.Sheets(1).Range("C1:E1").Copy ThisWorkbook.Sheets(1).Range("C" & LastRowMaster + 1 & ":E" & LastRowMaster + DataRowsSource).PasteSpecial xlPasteFormulas Skip: wbk.Close True Filename = Dir Loop End Sub ,则每次调用cmake构建时,这些设置都会被覆盖。因此,在这种情况下,您需要add WIN32 to executable target in CMakeList.txt or set CMAKE_WIN32_EXECUTABLE to true for cmake configure command