#include <iostream>
using namespace std;
void main(){
char name[20];
gets(name);
cout<<name<<endl;
}
I can’t found answer in google, function gets() is C or C++ language function ? Because in university I must use only C++ functions.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
gets()is a C function dating to the 1960’s, it does not do bounds checking and is considered dangerous, is has been kept all this years for compatibility and nothing else.Your code in valid and recommended C++ should be:
You should avoid to mix C specific features with C++ features as the string datatype/object. There are ways to use both, but as beginner you should stick to one or the other.
My personal recomendation, do C first, adn then transition to C++. Most C++ programmers are bad at pure C, the C language came first, and was used as the foundation environment for C++, but both have grown apart with time in more ways that you can imagine.
So unless you are studying object orientation simultaneosly with C++, all you will do is code in C with a C++ compiler. C++ is also very large in comparison to C. Templates and Object Oriented Programming facilities being the reasons to use C++ in the first place.
Pure C is still great for many things, is small and elegant. Its easier to get proficient at C than C++. C++ has grown to much to be manageable without sticking to a subset of features agreed by any developer team.