-1
    cout << "PODAJ NAZWĘ GRY: ";
    //fflush(stdin);
    //cin >> title;  
    getline(cin, title);
    cout << "PODAJ GATUNEK GRY: ";
    //fflush(stdin);
    //cin >> type;
    getline(cin, type);
    cout << "PODAJ PRODUCENTA GRY: ";
    fflush(stdin);
    //cin >> producer;
    getline(cin, producer);
    cout << "PODAJ ROK WYDANIA GRY: ";
    fflush(stdin);
    cin >> date;
    cout << "PODAJ DŁUGOŚĆ FABUŁY GRY: ";
    fflush(stdin);
    cin >> storyLenght;
    cout << "PODAJ TYP ŚWIATA GRY (OTWARTY/ZAMKNIĘTY): ";
    fflush(stdin);
    //cin >> worldType;
    getline(cin, worldType);
    obiektGameShop.createSingle(title, type, producer, date, ++index, 
        storyLenght, worldType);

After i run a code, "NAZWA GRY" is getting skipped, cin.ignore don't work. When I use only cin, after I type some title with space bar cin get skipped (for example, when title has 2 space bar code skip 2 cin's) https://i.stack.imgur.com/mPSrk.png

JaMiT
  • 12,175
  • 4
  • 14
  • 27
  • 1
    https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction – πάντα ῥεῖ Jun 01 '22 at 20:40
  • 2
    `fflush()` should never be applied to an input stream - it is only defined for output streams, and doesn't do what you expect even on those. `fflush(stdin)` produces Undefined Behavior, meaning that what it does is at best implementation-dependent and at worst utterly unpredictable. – Schol-R-LEA Jun 01 '22 at 20:40
  • `fflush(stdin);` is flat-out wrong, so lets see what you were trying with `ignore`. It should be closer to correct. – user4581301 Jun 01 '22 at 20:54

0 Answers0