473,594 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading from standart input stream using BinaryReader

// Open input file and create the BinaryReader.
br = new BinaryReader(ne w FileStream("Tes t.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 4789
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.co m

"Vitaly" <no****@ukr.net > wrote in message
news:dg******** ***@news.kiev.s ovam.com...
// Open input file and create the BinaryReader.
br = new BinaryReader(ne w FileStream("Tes t.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2429
by: Chris P. | last post by:
I have a C# application that connects to Perl application on a UNIX server. I am able to connect and communicate both directions with the server, but there are several occasions when it appears that the BinaryReader only reads part of the message sent by the server. Here is the main flow of my application. 1. Open Socket 2. Read 4 byte integer 3. Read byte array that is the size of the integer in step 2. 4. Put message in collection
1
1738
by: Michael Shestero | last post by:
Hello. General description of my knotty problem: I have a code (a function f) on standart C++ that perform some smart action. This code works as console application getting user input from fstream and putting output to another fstream. So, I can make easy console-application with void main(void) { f(&cin, &cout); }. This function f(...) works well. but it is very complex and it uses 'in' and 'out' in many places. It also sends them in...
2
1878
by: Cool Guy | last post by:
I use the following method to read a file: static byte ReadFile(string path) { FileStream stream = new FileStream(path, FileMode.Open); BinaryReader reader = new BinaryReader(stream); byte result = reader.ReadBytes((int)stream.Length); reader.Close(); return result;
2
12708
by: RP2001 | last post by:
I've serialized in various variables of various types (mainly CString, int, double) into an instantiated MFC CArchive class and saved it as a binary file. I am able to open the binary file and read out the individual variables fine with an MFC application. However I cannot read the binary file correctly with a C#.NET application, where I'm using the BinaryReader Class. Doing some debugging I noticed that the problem occured at this C#...
3
2617
by: poifull | last post by:
Hi All, What is the proper way to read a binary file into a byte? I am using BinaryReader to read from a Stream and call the ReadByte method of the BinaryReader object. The method I'm using leads to the second question. I got the "Conversion buffer overflow" error when I run the following code: Stream s = openFileDialog1.OpenFile();
9
6744
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
7
6052
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should populate a series of structures of specified variable composition. I have the structures created OK, but actually reading the files is giving me an error. Can I ask a simple question to start with: I'm trying to read the file using the...
2
1840
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again (an endless loop). i thought that BinaryReader.ReadByte advanced to the next byte? i had it time out after 1000 iterations, and keeps outputting the same byte. any help appreciated, my code is below: Imports System.io
3
3589
by: Yehia A.Salam | last post by:
Hello, I am trying to read from an xml file and put it to a memory stream so I can read it multiple times from the beginning using XmlTextReader without accessing the harddisk , I tried using FileStream but it locked the xml file so I can't access it anymore until I close the filestream, so my question is how to read from the file to the memorystream directly or read to the filestream first and the copy it to the memorystream? Thanks
0
7947
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8010
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5413
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.