can you tell me what is the equivalent of:

flushall()

in Turbo c++?

Thanks!

Im having a problem because of that.
Or,
what is the header file of it?

Thanks AGAIN :D

To flush the standard output, you can do std::cout.flush(); . As for the input buffer, you can't really flush it, but usually either std::cin.ignore(); , std::cin.clear(); or std::cin.sync(); will achieve what you want (i.e. ignore stray characters, clear error states, or re-synchronize with the buffer). Try those. I don't really know about flushall(), but a simple google search reveals that it is a POSIX-specific, C function and that it is deprecated in C++ (and modern OSes), but the header file for it is <stdio.h> (not cstdio, but the C library version finishing with .h).

The standard equivalent of flushall() is fflush(0) . The only thing flushall does is call fflush on all open streams, which is a feature that fflush already supports by passing a null pointer.

There's one caveat though. On implementations where flushall is supported, it typically "flushes" input streams too, where the flushing of an input stream clears all waiting input. This isn't standard behavior for fflush, which means that on implementations where the flushing of an input stream isn't supported, fflush(0) won't be a perfect analog to flushall.

To get a perfect analog on those implementations you need a way of acquiring handles to every open input stream, in which case it's a fairly trivial matter:

#include <cstdio>
#include <ios>
#include <istream>
#include <limits>

namespace jsw {
    using namespace std;

    template <typename CharT>
    void flush_istream(basic_istream<CharT>& in)
    {
        auto eof = char_traits<CharT>::eof();

        if (in.rdbuf()->sungetc() != eof)
            in.ignore(numeric_limits<streamsize>::max());
    }

    void flush_all()
    {
        // Flush all output streams
        std::fflush(nullptr);

        // "Flush" all input streams
        // C++0x ranged-for used for abstractifimication of the stream collection :D
        for (auto& stream : input_streams)
            flush_istream(stream);
    }
}

The actual storing isn't awkward unless you have different character typed streams (such as istream and wistream) in the same program. Just store some kind of handle to the stream in a collection each time you open a new one (not forgetting cin, of course).

This article has been dead for over six months. Start a new discussion instead.