By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,306 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

Reading from standart input stream using BinaryReader

P: n/a
// 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
Share this Question
Share on Google+
1 Reply


P: n/a
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.