Menu

what is new equivalent I/O for old C program

2007-08-07
2012-09-26
  • Nobody/Anonymous

    I want to use some old C code and firstly I am trying to
    compile and run it as a .cpp file. For I/O it uses:
    write(1,&c,1); //c is char
    write(1,string,count); //where char *string
    write(2,"EOF",4);
    if((nin=read(0,inbf,INBFSIZ))<=0)

    The compiler diagnostics are:
    ‘write’ undeclared (first use this function)
    ‘read’ undeclared (first use this function)
    No complaints by compiler after some obvious changes.

    The old includes are:

    include <stdio.h>

    include <math.h>

    How do I change it simply to do the same thing in today’s C++ ?
    I’m using Dev-C++ 4.9.9.2

     
    • Nobody/Anonymous

      Old write() and read() definitions are in <io.h>

      That header are in C:\Dev-Cpp\include, so you only need include

      include <io.h>

      Old newbie.

       
    • Nobody/Anonymous

      Exactly what I needed to know, thanks.

       
    • Nobody/Anonymous

      I should have been able to find that information
      myself somewhere. Yes, I have a book,
      perhaps not the right one. When I searched google,
      I didn't get the answer. There must be a c++
      reference on line somewhere that I could have
      searched. Is there one ?

       
    • Nobody/Anonymous

      Although exist in many Unix & Window C/C++ compilers, neither read() nor write() are C/C++ standar functions.

      To this questions I use a help file that comes with the Borland Builder C++ compiler. It has all these functions and a note about the appropriate header and compatibility (Unix, Windows, ANSI C and ANSI C++). Is the "C runtime Library Reference"; the BCB5RTL.HLP file, can be found in the Borland Site (documentation about the Borland C++ compiler).

      Old Newbie

       
      • Anonymous

        Anonymous - 2007-08-08

        Good tip for an off-line reference, but be cautious - the C Runtime library used by MinGW/GCC is the Microsoft Visual C++ v6 C library documented on-line here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/crthm.asp

        Note that the non-standard functions in the library are properly prefixed with an underscore so read() and write() are deprecated in favour of _read() and _write(). The non-underscored versions are supported for portability.

        Clifford

         
    • Nobody/Anonymous

      For a Standar C/C++ reference, esasily available, in Dev-C++ go to:

      Tools -> Check for Updates/Packages. There you can download the "C++ reference an Man pages". This package contains a combined chm (help file format) file with cppreference.com and the latest manpages. It include examples, but not the non-standar C/C++ functions.

      Old newbie.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.