0

that's my code, on the second time that i try to use the command cin.getline, it's just skipped, what's going on?

    #include <iostream>

using namespace std;

char nome [50], endereco[50];
int cep, telefone;

int main ()
{
    cout << "Digite seu Nome sem espacos " <<endl;
    cin.getline(nome, 50);
    cout<<"\n"<<endl;

    cout << "Digite seu Cep" <<endl;
    cin>> cep;
    cout<<"\n"<<endl;

    cout << "Digite seu Endereco" <<endl;
    cin.getline(endereco, 50);
    cout<<"\n"<<endl;

    cout << "Digite seu Telefone" <<endl;
    cin>> telefone;
    cout<<"\n"<<endl;

    cout <<"Seu nome e: " << nome <<endl;
    cout<<"\n"<<endl;

    cout <<"Seu cep e: " << cep<<endl;
    cout<<"\n"<<endl;

    cout <<"Seu endereco e: " <<endereco <<endl;
    cout<<"\n"<<endl;



    return 0;

}

My problem is on that part

cout << "Digite seu Endereco" <<endl;
        cin.getline(endereco, 50);
        cout<<"\n"<<endl;

That part is just skipped, i really dont know what's going on, could someomne please explain me this

  • Well i dont know why but putting the cin.ignore(); on that part worked, someone can explain me why? cout << "Digite seu Cep" <> cep; cin.ignore(); cout< – Carlos Allan Apr 28 '15 at 04:04
  • Put a `cin.ignore()` before each getline that occurs after a `cin >> x`. http://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction – 0x499602D2 May 01 '15 at 13:04

0 Answers0