Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:01:20+00:00 2026-06-01T15:01:20+00:00

The C++ FAQ over at parashift uses something similar to the following: while (cout

  • 0

The C++ FAQ over at parashift uses something similar to the following:

while (cout << "Enter an integer: " && !(cin >> foo))
{
    cin.clear();

    //feel free to replace this with just (80, '\n') for my point
    cin.ignore (numeric_limits<streamsize>::max(), '\n');
}

The cin.ignore (...), however, seems unnecessary. Why can’t I just use cin.sync()? It’s shorter and does not require a length. It’s also more versatile as it will work the same way whether or not there are any characters in the input buffer in the first place. I’ve tested this once in the same loop as I used with ignore and it worked the same way. Yet it seems every example involving this type of input validation uses ignore instead of sync.

What (if any) was the reasoning behind using ignore when there’s a much simpler alternative?

If it matters:
Windows
GCC
MinGW

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:01:21+00:00Added an answer on June 1, 2026 at 3:01 pm

    On an ifstream, the effect of sync() is implementation defined (per C++11, §27.9.1.5/19) — there’s no guarantee that it’ll do what you want (and no real guarantee of what it’ll do at all). In a typical case, it will be about equivalent to the ignore if and only if the stream is line buffered — but if the stream is unbuffered, it probably won’t do anything, and if the stream is fully buffered, it’ll probably do bad things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

c++ faq 35.16 http://www.parashift.com/c++-faq-lite/template-friends.html #include <iostream> template<typename T> class Foo { public: Foo(T const&
I've gone over the SWIG FAQ and dynamic module documentation and there seems to
I have a simple FAQ page in which each item has the following HTML
I was going over the C++ FAQ Lite online. I was browsing inlines again
According to the Memcached FAQ , the following occurs when an attempt to allocate
From: http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html#faq-19.9 Three keys: ROI, ROI and ROI. Every interface you build has a
The FAQ that comes with IronPython 2.0.1 says the following: You can define interfaces
http://www.parashift.com/c%2B%2B-faq/cpp-objs-passed-to-c.html The answer is in two parts. First part I guess is till the
From c++ FAQ: http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.9 Remember: delete p does two things: it calls the destructor
Basically from C++ FAQ I learned that: A virtual function allows derived classes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.