在Visual Studio 2010中查看控制台的输出?

我写一个简单的C#程序与一些输出( Console.WriteLine("..."); )。 问题是,每次运行它,我都看不到输出窗口中的程序输出。

“程序输出”标签已被检查,我已经将所有输出redirect到中间窗口,但无济于事。

我如何使看到程序的输出?

我不认为问题在于我的代码。 我尝试运行一个简单的程序,只输出一个string和readline“ala hello world”,我仍然无法看到任何输出。 问题是要么我在寻找错误的位置输出或Visual Studio行事。

debug.write方法也不起作用。

使用debug.Write ,它一切正常,但以前没有。 无论是在我重新启动之前与我喋喋不休,或者我只是需要rest一下,无论哪种方式现在都是好的。 感谢所有有帮助的评论=)

您可以使用System.Diagnostics.Debug.WriteSystem.Runtime.InteropServices方法将消息写入输出窗口。

这里有几件事要检查:

  1. 对于console.Write/WriteLine ,您的应用程序必须是控制台应用程序。 (右键单击解决scheme资源pipe理器中的项目,select“ 属性” ,然后查看“应用程序”选项卡中的“ 输出types ”组合应该是“ 控制台应用程序 ”(注意,如果您确实需要Windows应用程序或类库,不要改变这个控制台应用程序只是为了得到Console.WriteLine )。

  2. 您可以使用System.Diagnostics.Debug.WriteLine写入输出窗口(在VS中显示输出窗口, 查看 | 输出 )请注意,这些写操作只会发生在定义了DEBUG条件的构build中(默认情况下,debugging版本定义这个,发布版本不)

  3. 你可以使用System.Diagnostics.Trace.Writeline如果你想能够在非debugging版本中写入可configuration的“侦听器”。 (默认情况下,这将写入Visual Studio中的输出窗口,就像Debug.Writeline一样)

添加一个Console.Read(); 在你的程序结束。 它会阻止应用程序closures,你可以看到它的输出。

这是一个控制台应用程序,我刚挖出来,处理后,但在退出之前停止:

 class Program { static void Main(string[] args) { DummyObjectList dol = new DummyObjectList(2); dol.Add(new DummyObject("test1", (Decimal)25.36)); dol.Add(new DummyObject("test2", (Decimal)0.698)); XmlSerializer dolxs = new XmlSerializer(typeof(DummyObjectList)); dolxs.Serialize(Console.Out, dol); Console.WriteLine(string.Empty); Console.WriteLine(string.Empty); List<DummyObject> dolist = new List<DummyObject>(2); dolist.Add(new DummyObject("test1", (Decimal)25.36)); dolist.Add(new DummyObject("test2", (Decimal)0.698)); XmlSerializer dolistxs = new XmlSerializer(typeof(List<DummyObject>)); dolistxs.Serialize(Console.Out, dolist); Console.Read(); // <--- Right here } } 

或者,您可以简单地在最后一行添加一个断点。

Ctrl + F5运行该程序而不是F5

System.Diagnostics.Debug.WriteLine()将工作,但你必须在正确的地方寻找输出。 在Visual Studio 2010中,在菜单栏上,单击debugging – > Windows – > 输出 。 现在,在停靠在错误列表旁边的屏幕底部,应该有一个输出标签。 点击它并仔细检查它是否显示下拉列表中debuggingstream的输出。

PS:我认为输出窗口显示在全新的安装,但我不记得了。 如果没有,或者意外closures了,请按照这些说明操作。

要保持打开你的Windows控制台,而不是使用其他输出方法,而不是标准输出streamcout去你的项目名称 – >属性 – >连接器 – >系统。

一旦出现,select子系统选项卡并标记控制台(/ SUBSYSTEM:CONSOLE)。 一旦你完成了这个任务,只要你想编译,使用Ctrl + F5(开始不debugging),你的控制台将保持打开状态。 🙂

我出于某种原因经常遇到这种情况,我无法理解为什么没有提到这个解决scheme:

点击查看输出 (或者只是按住Ctrl键并点击W> O)

然后控制台输出将显示在错误列表本地监视窗口的位置。

注意:我正在使用Visual Studio 2015。

在Program.cs中,介于:

 static int Main(string[] agrs) { 

和你的代码的其余部分,添加:

 #if DEBUG int rtn = Main2(args); Console.WriteLine("return " + rtn); Console.WriteLine("ENTER to continue."); Console.Read(); return rtn; } static int Main2(string[] args) { #endif 

你可以创build两个小方法,一个可以在程序开始时调用,另一个在结束时调用。 您还可以使用Console.Read(),以便在最后一个写入行之后程序不会closures。

通过这种方式,您可以确定何时执行function以及程序何时存在。

 startProgram() { Console.WriteLine("-------Program starts--------"); Console.Read(); } endProgram() { Console.WriteLine("-------Program Ends--------"); Console.Read(); }