Reputation: 16910
How can i redirect my input and output to a file?
Example if i execute my program as :-
abc.exe < input.txt > output.txt
It should read input from input.txt and write output to output.txt
Thanks in advance :)
Upvotes: 0
Views: 1023
Reputation: 9515
System.Console.SetIn(TextReader newIn)
System.Console.SetOut(TextWriter newOut)
Would be good if you want to vary outputs during program's run.
Upvotes: 0
Reputation: 2220
Calling a console application with the < and > will redirect input and output. Just use Console.Read or ReadLine and Write, WriteLine etc. in your program.
Upvotes: 0
Reputation: 20140
you mean this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String s;
while ((s = Console.In.ReadLine())!= null)
{
Console.Out.WriteLine(s);
}
}
}
}
Upvotes: 3