IO question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bor de Wolf

    #1

    IO question

    Please tell me why I am not getting out what I put in.

    FileStream nrIn = new
    FileStream("Dat aCount.prl",Fil eMode.OpenOrCre ate,FileAccess. Read) ;
    BinaryReader inr = new BinaryReader(nr In);
    recordNumber = inr.Read();
    nrIn.Close();
    Console.WriteLi ne("The current recordnumber is{0}",recordNu mber.ToString() );
    Console.Write(" Enter record number: ");
    recordNumber = Console.Read();
    FileStream nrOut = new
    FileStream("Dat aCount.prl",Fil eMode.Create,Fi leAccess.Write) ;
    BinaryWriter outW = new BinaryWriter(nr Out);
    outW.Write(reco rdNumber);
    nrOut.Close();






  • Michael A. Covington

    #2
    Re: IO question


    "Bor de Wolf" <bor@bor.bor> wrote in message
    news:1061200438 .945299@evisp-news-01.ops.asmr-01.energis-idc.net...[color=blue]
    > Please tell me why I am not getting out what I put in.
    >
    > FileStream nrIn = new
    > FileStream("Dat aCount.prl",Fil eMode.OpenOrCre ate,FileAccess. Read) ;
    > BinaryReader inr = new BinaryReader(nr In);
    > recordNumber = inr.Read();
    > nrIn.Close();
    > Console.WriteLi ne("The current recordnumber[/color]
    is{0}",recordNu mber.ToString() );[color=blue]
    > Console.Write(" Enter record number: ");
    > recordNumber = Console.Read();
    > FileStream nrOut = new
    > FileStream("Dat aCount.prl",Fil eMode.Create,Fi leAccess.Write) ;
    > BinaryWriter outW = new BinaryWriter(nr Out);
    > outW.Write(reco rdNumber);
    > nrOut.Close();[/color]

    Related to your earlier question. Console.Read() reads one character. This
    is very different from read in Pascal.



    Comment

    • Duncan  McNutt

      #3
      Re: IO question

      int Console.Read();
      Reads the next character from the standard input stream.

      [Visual Basic]
      Public Shared Function Read() As Integer
      [C#]
      public static int Read();
      [C++]
      public: static int Read();
      [JScript]
      public static function Read() : int;
      Return Value
      The next character from the input stream, or negative one (-1) if no more
      characters are available.

      Exceptions
      Exception Type Condition
      IOException An I/O error occurred.

      Remarks
      This method will not return until the read operation is terminated; for
      example, by the user pressing the enter key. If data is available, the input
      stream contains what the user entered, suffixed with the environment
      dependent newline character.

      Example
      [Visual Basic]
      Dim i As Integer
      Dim c As Char
      While True
      i = Console.Read()
      If i = - 1 Then
      Exit While
      End If
      c = Microsoft.Visua lBasic.Chr(i)
      Console.WriteLi ne("Echo: {0}", c)
      End While
      Console.WriteLi ne("Done")
      Return 0
      [C#]
      int i;
      char c;
      while (true)
      {
      i = Console.Read ();
      if (i == -1) break;
      c = (char) i;
      Console.WriteLi ne ("Echo: {0}", c);
      }
      Console.WriteLi ne ("Done");
      return 0;
      [JScript]
      var i : int;
      var c : char;
      while (true)
      {
      i = Console.Read ();
      if (i == -1) break;
      c = char(i);
      Console.WriteLi ne ("Echo: {0}", c);
      }
      Console.WriteLi ne ("Done");
      return 0;
      [C++] No example is available for C++. To view a Visual Basic, C#, or
      JScript example, click the Language Filter button in the upper-left corner
      of the page.

      Requirements

      --

      Duncan McNutt
      Microsoft Product Deactivation Team
      --


      "Michael A. Covington" <Michael@Coving tonInnovations. com> wrote in message
      news:OAeFQzYZDH A.1384@TK2MSFTN GP10.phx.gbl...[color=blue]
      >
      > "Bor de Wolf" <bor@bor.bor> wrote in message
      > news:1061200438 .945299@evisp-news-01.ops.asmr-01.energis-idc.net...[color=green]
      > > Please tell me why I am not getting out what I put in.
      > >
      > > FileStream nrIn = new
      > > FileStream("Dat aCount.prl",Fil eMode.OpenOrCre ate,FileAccess. Read) ;
      > > BinaryReader inr = new BinaryReader(nr In);
      > > recordNumber = inr.Read();
      > > nrIn.Close();
      > > Console.WriteLi ne("The current recordnumber[/color]
      > is{0}",recordNu mber.ToString() );[color=green]
      > > Console.Write(" Enter record number: ");
      > > recordNumber = Console.Read();
      > > FileStream nrOut = new
      > > FileStream("Dat aCount.prl",Fil eMode.Create,Fi leAccess.Write) ;
      > > BinaryWriter outW = new BinaryWriter(nr Out);
      > > outW.Write(reco rdNumber);
      > > nrOut.Close();[/color]
      >
      > Related to your earlier question. Console.Read() reads one character.[/color]
      This[color=blue]
      > is very different from read in Pascal.
      >
      >
      >[/color]




      Comment

      Working...