/tmp/ccSx0L0H.o: In function `employee::getdata()':
multi.cc:(.text._ZN8employee7getdataEv[employee::getdata()]+0x31): warning: the `gets' function is dangerous and should not be used.

#include<iostream>
#include<string>
using namespace std;

const int len = 25;

class employee
{

private :

char name[len];

unsigned long enumb;

public :

void getdata()
{
cout<<"Enter the name"<<"\n";

gets(name);

cout<<"Enter Employee name \n";

cin>>enumb;

}
void putdata()
{

cout<<"Name :"<<name<<"\t";
cout<<"Emp num :"<<enumb<<"\t";
cout<<"Basic salary :"<<basics<<"\n";

}

protected :

float basics ;

void getbasics()
{
cout<<"Enter the basics :";
cin>>basics;
}

};


class Manager : public employee
{

private :
char title[len];
public :
void getdata()
{
employee::getdata();
getbasics();
cout<<"Enter the title :\n";
gets(title);
cout<<"\n";
}
void putdata()
{
employee::putdata();
cout<<"Title :"<<title<<endl;
}


};


main()
{
Manager m1, m2;
cout<<"Manager 1";m1.getdata();
cout<<"Manager 2";m2.getdata();
m1.putdata();
m2.putdata();
return 0;
}

>warning: the `gets' function is dangerous and should not be used.
It's pretty self-explanatory, I think. gets is dangerous and shouldn't be used. So stop using it. :icon_rolleyes: May I suggest cin.getline as a replacement for gets? It's somewhat of a bad practice to mix the C style I/O functions with iostreams anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.