468,484 Members | 2,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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 4519
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 NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.