MattMatt2000
MattMatt2000

Reputation: 622

Writing to the console's standard output using StreamWriter

Disclaimer: I come from a C++ background and started C# recently.

For some reason, I cannot write to the console's standard output like this:

new StreamWriter(Console.OpenStandardOutput()).Write("Stackoverflow");

Any suggestions?

Upvotes: 0

Views: 1974

Answers (1)

Killer Death
Killer Death

Reputation: 459

sw = new StreamWriter(Console.OpenStandardOutput());
sw.AutoFlush = true;
Console.SetOut(sw);
sw.WriteLine("Stackoverflow");

Upvotes: 4

Related Questions