How to ignore INPUT in C++

Правка en1, от pop1912, 2021-01-21 13:32:28

Hi, I'm using "cin.ignore()" to ignore the input. I want only the 2nd integer to be displayed for this sample Input, I'm getting WA for some Test Cases, What is wrong in my code?:

Testcase 1:(Output should be "1")

2 1
carrots?
bunnies

Testcase 2:(Output should be "5")

1 5
sovl problmz

My Code:

#include<iostream>
using namespace std;

int main() {
    int a;
    cin.ignore();
    cin>>a;
    cin.ignore();
    
    cout<<a;
    
    return 0;
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский pop1912 2021-01-21 13:32:28 575 Initial revision (published)