Answer the question
In order to leave comments, you need to log in
How to read from input and output to output in C#?
What should the input from input.txt look like, and the output to output.txt, when solving Olympiad problems?
Answer the question
In order to leave comments, you need to log in
using System;
using System.IO;
namespace InputOutputExample
{
class Program
{
static void Main(string[] args)
{
string inputFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "input.txt");
string outputFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "output.txt");
using var input = new StreamReader(File.OpenRead(inputFile));
Console.SetIn(input);
using var output = new StreamWriter(File.OpenWrite(outputFile));
Console.SetOut(output);
string line = null;
while ((line = Console.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question