471,311 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,311 software developers and data experts.

Reading from standart input stream using BinaryReader

// Open input file and create the BinaryReader.
br = new BinaryReader(new FileStream("Test.dat",
FileMode.Open,
FileAccess.Read));

// Read binary data.
d = br.ReadDouble();

A question is how to do the same but read from standard input stream … like
Console.In.

How to Assign the BinaryReader to the standard input stream which actually
has type TestReader?

Any suggestion?

Nov 17 '05 #1
1 4638
Vitaly,

You don't want to do this. When you use a BinaryReader, it is not doing
a conversion when you read a double. When you call ReadDouble, it actually
reads four bytes, and takes that as the four byte representation of the
double.

The standard console stream is different. It is going to feed you
characters (hence the use of a TextReader to support it). The four bytes
that represent the double are going to look like garbage if you printed them
out on screen.

Instead, you want to read the line from the console, and then pass that
to one of the methods on the Convert class, to perform a conversion from a
string to a double.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vitaly" <no****@ukr.net> wrote in message
news:dg***********@news.kiev.sovam.com...
// Open input file and create the BinaryReader.
br = new BinaryReader(new FileStream("Test.dat",
FileMode.Open,
FileAccess.Read));

// Read binary data.
d = br.ReadDouble();

A question is how to do the same but read from standard input stream …
like
Console.In.

How to Assign the BinaryReader to the standard input stream which actually
has type TestReader?

Any suggestion?


Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Cool Guy | last post: by
9 posts views Thread by jeff M via .NET 247 | last post: by
7 posts views Thread by John Dann | last post: by
2 posts views Thread by Mad Scientist Jr | last post: by
3 posts views Thread by Yehia A.Salam | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.