Thread: C libaries in C++

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    8

    C libaries in C++

    Hi all.
    Is it an okay practice to use c libary functions in C++
    or are there equivalent libaries in C++ .
    is the above poor c++ programing ?

    or could it cause problems ?

    Thanks

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The standard C library is included in the standard C++ library. Under the old standard, a C program would, for the most part, compile fine as a C++ program with no change necessary. With the new standard, they changed the method of including C libraries.
    Code:
    #include <stdlib.h> /* C, Old C++ */
    #include <cstdlib> /* New C++ */
    #include <iostream.h> /* Old C++ */
    #include <iostream> /* New C++ */
    
    using namespace std; /* required in new C++ */
    I hope that's understandable. Notice that not only were the .h extensions dropped for standard header files, but C libraries were preceded with 'c's.

    As for the issue of whether or not it is bad practice, I'm going to give you an answer you don't want to hear. "It depends". Some functions have been replaced with version that are arguable better. For example, getting user input has been upgraded substantially to an Object-Oriented version. In most cases, better to use this. The same goes for string processing. But things like the time functions - are for the most part left as they were in C. And don't forget to include OS APIs and others in what may be a better function than the original C libraries.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    8
    Thanks
    not heard or read about cstdlib.
    but just starting C++.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    3
    The C library is a lot better for memory management than the C++ library. I typically use the C library to do memory comparisons. I also use it for random numbers and for formatted output to strings. Why? We'll because doing a sprintf() is a lot easier than using the string object and converting numbers to strings yourself. I take the easy route.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's the difference betwem these two libaries
    By Zahl in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2003, 01:39 PM
  2. How do I use graphics libaries in Linux C/C++?
    By Kuplex in forum Game Programming
    Replies: 3
    Last Post: 12-03-2001, 12:16 PM