[c#] Seeing the console's output in Visual Studio 2010?

I am writing a simple C# program with some outputs (Console.WriteLine("...");). The problem is, each time I run it, I cannot see the program's output in the output window.

The "program output" tag is already checked, and I already redirected all outputs to the intermediate window but to no avail.

How do I enable seeing the program's output?

I don't think the problem lies with my code. I tried running a simple program that just outputs a string and readline "ala hello world" and I am still unable to see any output. The problem is either with me looking for the output in the wrong location or Visual Studio acting out.

The debug.write method also doesn't work.

Using debug.Write, it all works, though it didn't before. Either something bugged out with me before I restarted or I just need to take a break, either way it's all good now. Thanks all for the helpful comments =)

This question is related to c# visual-studio-2010 visual-studio

The answer is


System.Diagnostics.Debug.WriteLine() will work, but you have to be looking in the right place for the output. In Visual Studio 2010, on the menu bar, click Debug -> Windows -> Output. Now, at the bottom of the screen docked next to your error list, there should be an output tab. Click it and double check it's showing output from the debug stream on the dropdown list.

P.S.: I think the output window shows on a fresh install, but I can't remember. If it doesn't, or if you closed it by accident, follow these instructions.


To keep open your windows console and to not use other output methods rather than the standard output stream cout go to Name-of-your-project -> Properties -> Linker -> System.

Once there, select the SubSytem Tab and mark Console (/SUBSYSTEM:CONSOLE). Once you have done this, whenever you want to compile use Ctrl + F5 (Start without debugging) and your console will keep opened. :)


I run into this frequently for some reason, and I can't fathom why this solution hasn't been mentioned:

Click View ? Output (or just hold Ctrl and hit W > O)

Console output then appears where your Error List, Locals, and Watch windows are.

Note: I'm using Visual Studio 2015.


Add a Console.Read(); at the end of your program. It'll keep the application from closing, and you can see its output that way.

This is a console application I just dug up that stops after processing but before exiting:

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
    }
}

Alternatively, you can simply add a breakpoint on the last line.


You could create 2 small methods, one that can be called at the beginning of the program, the other at the end. You could also use Console.Read(), so that the program doesn't close after the last write line.

This way you can determine when your functionality gets executed and also when the program exists.

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


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

Here are a couple of things to check:

  1. For console.Write/WriteLine, your app must be a console application. (right-click the project in Solution Explorer, choose Properties, and look at the "Output Type" combo in the Application Tab -- should be "Console Application" (note, if you really need a windows application or a class library, don't change this to Console App just to get the Console.WriteLine).

  2. You could use System.Diagnostics.Debug.WriteLine to write to the output window (to show the output window in VS, got to View | Output) Note that these writes will only occur in a build where the DEBUG conditional is defined (by default, debug builds define this, and release builds do not)

  3. You could use System.Diagnostics.Trace.Writeline if you want to be able to write to configurable "listeners" in non-debug builds. (by default, this writes to the Output Window in Visual Studio, just like Debug.Writeline)


Press Ctrl + F5 to run the program instead of F5.


In Program.cs, between:

static int Main(string[] agrs)
{

and the rest of your code, add:

#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

Visual Studio is by itself covering the console window, try minimizing Visual Studio window they are drawn over each other.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to visual-studio-2010

variable is not declared it may be inaccessible due to its protection level SSIS Excel Connection Manager failed to Connect to the Source This project references NuGet package(s) that are missing on this computer Gridview get Checkbox.Checked value error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj What is the difference between Visual Studio Express 2013 for Windows and Visual Studio Express 2013 for Windows Desktop? Attach (open) mdf file database with SQL Server Management Studio What is and how to fix System.TypeInitializationException error? Could not load file or assembly "Oracle.DataAccess" or one of its dependencies IIS error, Unable to start debugging on the webserver

Examples related to visual-studio

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references