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
Printable View
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
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.
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.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++ */
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.
Thanks
not heard or read about cstdlib.
but just starting C++.
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.