help, new to C++

This is a discussion on help, new to C++ within the C++ Programming forums, part of the General Programming Boards category; hi, what is the use of cin.ignore()? i am new to C++ i have idea about C, thanks@@@@@@@@@@@@@@@...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    1

    Question help, new to C++

    hi,
    what is the use of cin.ignore()? i am new to C++ i have idea about C,
    thanks@@@@@@@@@@@@@@@

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    it causes characters in the input buffer to be read and discarded.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    6
    something like getch()?


  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    no not really...

    consider it like this....

    when you use cin>> the newline is left in the stream rather than discarded so if you then try a cin.get() or a cin.getline() it will appear that that statement was skipped because all it picked up was the newline and so we can use cin.ignore() to ignore the last character in the input buffer. It can be useful for removing bad input from the buffer to.
    cin.ignore() by default ignores 1 char. You can also use it like this...
    cin.ignore(100,'\n') this will ignore up to 100 chars or a newline whichever comes first.

    Thats about all there is to cin.ignore()
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21