I started learning strings and string functions (from a book) , I learned functions like strcpy and strcat and strncat..etc
So I started to practice using them in simple programs to get a sense of what they do.
Then I was surprised later that in the book it tells me that i have to use #include <cstring> in order to use all these string functions.
I have tried using string functions more than once without including <cstring> so why?
The only header file i included was <iostream> and yet i was able to use string functions.
Please someone explain to me why the string functions worked without <cstring> and do I need to include it to use string functions, and if no what are the uses of <cstring>;
First of all, you absolutely need to consider switching to
std::string. Manual memory allocation, while being an interesting and sometimes challenging task, should not be a part of your everyday job.Having said that, probably the
<cstring>was #included by some other header you are using in your project. However it’s better not to depend on the other headers including<cstring>(no one guarantees that they will do always and for every compiler), and include it where appropriate.