开发者

Why its not working?

BinaryReader br = new BinaryReader(Console.OpenStandardInput());
BinaryWriter bw = new BinaryWriter(Console.OpenStandardOutput());

int n = br.ReadInt32();
bw.Write(n);

always getting this error:

Unhandled Exception: System.IO.EndOfStreamException: Failed to read past end of stream.
at System.IO.BinaryReader.FillBuffer (Int32 numBytes) [0x00000] in <filename unknown>:0 
at System.IO.BinaryReader.ReadInt32 () [0x00000] in <filename unknown>:0 
at Program.Main () [0x00025] in /home/skydos/ACM/Csharp/Csharp/Main.cs:24 

Is there 开发者_开发百科any way to make reading data in C# faster from Console?


Are you writing anything to the standard input of your program? The error says there's no data available, quite simple.


There are plenty of examples in the MSDN documentation on how to go about dealing with System.IO stuff. Maybe this link will get you started?

http://msdn.microsoft.com/en-us/library/ms404278.aspx?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.IO.BINARYREADER);k(TargetFrameworkMoniker-%22.NETFRAMEWORK&k=VERSION=V4.0%22);k(DevLang-CSHARP)&rd=true

If speed is your main concern, perhaps this article at Code Project will give you some ideas:

http://www.codeproject.com/KB/files/fastbinaryfileinput.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜