0

I have the simple two code sections:

cin >> a;
cin >> g;

And:

cin >> a;
getline(cin, g);

Wuth the first section, I don't need to clear the buffer and the program will run softly. Conversely, with the second section I will have to put a buffer cleaner. Why is that?

Cœur
  • 32,421
  • 21
  • 173
  • 232
  • 1
    Because `cin` reads until white space, but `getline` reads until `\n`. – Eli Sadoff Nov 07 '16 at 21:36
  • 2
    `cin` also reads to a type, whereas `getline` just reads the entire line. What types are `a` and `g`? – Eli Sadoff Nov 07 '16 at 21:36
  • @EliSadoff string and int – lkj lkjlkj Nov 07 '16 at 21:44
  • @EliSadoff What do you mean by 'reads to a type'? If a is integer and I put a string in it, So what happends? I didnt really understood what you saied, and also didnt undrstood the duplicate answer. Whe cin after cin works? does it clean the buffer automatically ang getline not? – lkj lkjlkj Nov 07 '16 at 22:14

0 Answers0