The execution of the above given program is not taking my String datatype input i.e variable 'name' and is directly skipping to rollno for taking input? Its a simple program in which I'm making a class with 2 functions getdata putdata and Im simply calling it!
#include <iostream>
#include <string>
using namespace std;
class Student
{
int rollno;
string name;
float fee;
public:
void getdata();
void putdata();
};
void Student::getdata()
{
cout<<"Enter rollno. : ";
cin>>rollno;
cout<<"Enter name : ";
getline(cin,name);
cout<<"Enter fee : ";
cin>>fee;
}
void Student::putdata()
{
cout<<"---Information-----"<<endl;
cout<<"rollno : "<<rollno<<endl;
cout<<"name : "<<name<<endl;
cout<<"fee : "<<fee<<endl;
}
int main()
{
Student ss;
ss.getdata();
ss.putdata();
return 0;
}
Output:
Enter rollno. : 24
Enter name : Enter fee : 2000
---Information-----
rollno : 24
name :
fee : 2000
Process returned 0 (0x0) execution time : 15.887 s
Press any key to continue.