I'm a beginner in programming. While learning tried to write the code below. The problem is when I try to get gamar's surname it does not work it, just skips the line with getline(). But when I comment the lines above getline() it works. Where do I make mistake?
#include <iostream>
#include <string>
#include "class.h"
using std::cout;
using std::endl;
using std::cin;
using std::string;
int main(){
Person gamar;
cout<<"Enter Gamar's height: ";
cin>>gamar.height;
cout<<"Enter Gamar's weight: ";
cin>>gamar.weight;
cout<<"Enter Gamar's surname: ";
getline(cin,gamar.surname );
cout<<"Gamar's surname: "<<gamar.surname<<endl;
cout<<"Gamar's height: "<<gamar.height<<endl;
cout<<"Gamar's weight: "<<gamar.weight<<endl;
}
And here is the header file:
using std::string;
class Person{
public:
string surname;
int weight;
int height;
};