0

/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.

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Narue
0

#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;
}

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.