here is my code and if you run it you 'll see that it has a bug


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

class example
{
    public:
        example();
        void print(){cout<<itsName<<endl<<itsNumber<<endl<<endl;}
    private:
        string itsName;
        int itsNumber;

};

example::example()
{
    cout<<"Enter Name"<<endl;
    getline(cin,itsName);
    cout<<"Enter Number"<<endl;
    cin>>itsNumber;
}
int main()
{
    example a[3];
    for(int i=0;i<3;i++)
    {
        a[i].print();
    }
    return 0;
}
BUT if i change getline(cin,itsName) with cin>>itsName it works fine
can you tell me why?

ps i'm a novice (c++) programer so there is a high possibility that my question is silly