How do i redirect input output to file instead of stdout?
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 :)
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);
}
}
}
}
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.
System.Console.SetIn(TextReader newIn)
System.Console.SetOut(TextWriter newOut)
Would be good if you want to vary outputs during program's run.
精彩评论