This may be due to a '\n' left in the stream from some other part of your program. Flush the stream before using getline(). What chandanadhikari suggested is absolutely right. Try using cin.ignore() or cin.sync and cin.clear ,your problem will be solved.
class x
{
char ch[30];
int num;
public:
void getdata()
{
cout<<"Enter string:\n";
cin.ignore();
getline(cin,s);
cout<<"Enter a number :";
cin>>num;
}
};