Reputation: 93
Really new to this, I've read the answers on here and they have helped so far but I am still a bit stuck.
I have managed to create a program that displays the users starsign from DOB input.
Now I want to send the results to a text file. I can create the file but I do not know how to send the console output/result of the program to the file.
Upvotes: 4
Views: 13524
Reputation: 3925
Console.WriteLine("Hello World");
FileStream fs = new FileStream("Test.txt", FileMode.Create);
// First, save the standard output.
TextWriter tmp = Console.Out;
StreamWriter sw = new StreamWriter(fs);
Console.SetOut(sw);
Console.WriteLine("Hello file");
Console.SetOut(tmp);
Console.WriteLine("Hello World");
sw.Close();
http://msdn.microsoft.com/en-us/library/system.console.setout.aspx
Upvotes: 7
Reputation: 73
If you have calculated the date of birth and written it to the console, you have the answer stored in a variable, then all you need to do is write that out to the text file - unless I am missing some in the problem?
http://msdn.microsoft.com/en-us/library/aa287548(v=vs.71).aspx
Upvotes: 1