Using stdio.h in a C++ program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hanaa
    New Member
    • Nov 2007
    • 44

    Using stdio.h in a C++ program

    Hello..

    Is it okay to use functions such as setvbuf (that is defined in stdio.h) in a C++ program?
    I include stdio.h in the program and it works. Yet, I wonder if its okay.. stdio.h is a part of the standard C library and not standard C++ library, if I'm not wrong.
    I also want to know if many such other functions can be used in C++ programming. Is there a clear line between the standard libraries for C and C++? Is using either in the other's programs a bad thing to do?

    (I'm using GNU's DJGPP on Windows XP).

    Thanks a ton. I love bytes.

    Hanaa.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    C functions are supposed to work in C++. Some functions can't be mixed, e.g. malloc/free and new/delete should be kept far from each other. C++ has more flexible functions/classes and methods. From a more purist point of view there is no need to use the functions available in stdio.h, C++ has its alternatives that can do what their C counterparts do and more. Bookmark this site for a convenient reference.

    kind regards,

    Jos

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      setvbuf is mentioned in the c++ standard, and is expected to work as described in the C standard unless compiler/library itself has bugs.

      Comment

      • hanaa
        New Member
        • Nov 2007
        • 44

        #4
        Thank you..
        1)Would you also tell me where I can find the Standards?

        2) Would someone answer the others questions too, the questions in my first post here (if using C's functions in C++ programs in a bad idea).

        Comment

        • manontheedge
          New Member
          • Oct 2006
          • 175

          #5
          Originally posted by hanaa
          Thank you..
          1)Would you also tell me where I can find the Standards?

          2) Would someone answer the others questions too, the questions in my first post here (if using C's functions in C++ programs in a bad idea).

          I'm not sure about "finding standards", but generally, when working with C++, you can tell C and C++ apart by the header files. C++ doesn't use header files with a '.h', for example #include <stdio.h> is obviously a C standard ( because of the .h ), though obviously if you create a header file yourself, you'll use a '.h', but that's different.

          In general, mixing C with C++ is frowned upon. It's just bad practice, though you will find those who do it.

          Comment

          • hanaa
            New Member
            • Nov 2007
            • 44

            #6
            Oh I didnt know the .h thing. Strange. I always wrote <iostream.h> in Turbo c++ version 3.0. Yeah , but in GCC, it accepts only <iostream>.

            Hmmm. Okay. But I found nothing equivalent to setvbuf() (in stdio.h) in any other header file. Is there any, in a C++ header file?

            Thank you.

            Comment

            • newb16
              Contributor
              • Jul 2008
              • 687

              #7
              #include <cstdio>

              It, in turn, most likely incudes stdio.h

              Comment

              Working...