Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

pop1912's blog

By pop1912, history, 6 weeks ago, In English

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;
}
 
 
 
 
  • Vote: I like it
  • -22
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Just read input into a dummy variable and do not use it.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yup, that worked, but using "cin.ignore()" is not working... any Idea?

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Have you read doc on the istream::ignore()? It should not work in your case.