Hello, I am learning string functions from a book, however, the book was published in 2003 so some things may no longer be relevant. The functions I am trying out is strcpy, strcmp strcat, and strlen. When I try and use the first three, my compiler complains that they are unsafe and are deprecated. But when I check the tutorials on this site I do not see anything about these functions no longer being used. Are these functions are still being used today, are they old, is there something wrong with my compiler?
Those are C functions. C++ supports them, because that's what C++ does when it comes to everything it got from C, but C++ has std::string which is a proper string class.
Where C has the dangerous strcpy function, in C++ you just use = and the string class takes care of it for you, safely.
If you're learning C++, start with the actual C++. Start with actual C++ string class.
Its a c++ book i am learning from, and its teaching these functions. It is teaching two methods of strings, it says, "c++ supports two types of strings, the most commonly used, the null terminated string, which is a null terminated array" Which is, what I believe these functions are used for? and then the book talks about a sting defined by c++ which I believe is what you are talking about.
Is the null terminated string still the most commonly used then? I am guessing it is not by your comment?
String object was a latecomer to c++, added with the first STL implementation I think? So old books will still teach the old way, as do old professors, sadly.
Your book covers both but has it backwards; String object is the most commonly used in new code written in the last 10-15 years at least. If you look at all code since the dawn of time, the C style wins hands down.
So the answer is .. it depends. Technically the author is probably right in that most code probably does use C style, due to years and volume and some places that still teach it. There is also a hardware / integration issue: many devices and quite a few software packages want C-style strings to interface to them, forcing even new, modern code to use them at least a little bit for at least the interface part (for small things, you may end up just using c-style the whole way). For example, the database program I write plug-ins for now and the GPS &DMU devices I used at my last job all spoke C-style. And string is faster than c style on some things, so for max speed you would need both which is an unholy mess in code.
there are 2 or 3 things you can do slightly easier/better in C-style, at the risk of 'if you screw it up, its hard to debug and deal with' like all arry/pointer code. The old power/responsibility thing, most modern folks err on the side of responsible as computing power today make it harder to justify goofy shortcuts to save a few billionths of a second and every year the wall clock savings decrease.
the things where c-style is slightly better IMHO..
- serialized data where you have to deal with string members in some annoying way while a char array fixed size member can be directly shoved thru.
- find is not boolean, strstr() effectively is. sometimes you just want to know if its there. String object can do it, but its clunky.
- destructive parsing. you can jack a 0 over a delimiter and get substring values via pointers more efficiently (destroys the input) than splitting up a string.
-and not really fair, mad hax stuff where you do weird pointer/magic stuff that should not ever be done except for amusement purposes is well suited to C style.