gets() is a C function dating back to the 1960s, it does not check boundaries and is considered dangerous, it has been stored all these years for compatibility and nothing more.
Your code in valid and recommended C ++ should be:
You should avoid combining special C functions with C ++ functions as a data type / string object. There are ways to use both, but as a beginner you should stick with one or the other.
My personal approval, first C, and then switching to C ++. Most C ++ programmers do not work well in pure C, the C language first appeared and was used as the basis for C ++, but both grew over time in many ways that you can imagine.
So, if you do not study the orientation of objects at the same time as C ++, all you do is C code with a C ++ compiler. C ++ is also very large compared to C. The patterns and object-oriented programming tools that are the reasons for using C ++ in the first place.
Pure C is still great for many things, small and elegant. It's easier to master C than C ++. C ++ has been greatly improved so as not to succumb to a subset of the functions agreed upon by any development team.
source share