简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM