Please enlighten a novice: How can it be guaranteed that you can mix two
different IO libraries and still get 100% function?
Please _do not_ use both IO libraries for input from same stream.
Flushing output is a performance loss but works. No characters gets lost
and the flush solves the problem with output through the two libraries
getting incorrectly mixed with each other.
Flushing of input is a lossy project - throwing away characters. You just
can't throw away characters eaten by one IO library and then expect the
other IO library to not be affected.
In some special circumstances you might get a program to work with a mix
of C and C++ input from the console. However, if you change to another
compiler or move the code to another OS, you don't know how your program
will behave. Different implementations of the libraries behaves
differently. However, this isn't a problem: If you use just C or just C++
for a specific stream, you are using the libraries as they are indended,
and then they will behave as expected.
The problem is similar to trying to set output position of a file with
fseek(FILE*,...) and then use a output stream to write information. The
output stream doesn't know about the fseek() and the output gets written
to the wrong location.
If we think about standards: The C++ standard can't have full control over
the internals of the C library, while the C standard obviously haven't any
control over the C++ libraries.
So, I repeat it once more: Avoid mixing getche() with cin!
In a win32 console, you can always use SetConsoleMode() with the
ENABLE_ECHO_INPUT flag to control input echo.
/Per W
On Mon, 6 Sep 2004, Noorez Kassam wrote:
> How do I flush the input buffer after using getch() or getche()? I use
> cin.sync() after using cin? How can I do it for the other functions?
>
> _________________________________________________________________
> Take advantage of powerful junk e-mail filters built on patented Microsof=
t=AE
> SmartScreen Technology.
> http://join.msn.com/?pgmarket=3Den-ca&page=3Dbyoa/prem&xAPID=3D1994&DI=3D=
1034&SU=3Dhttp://hotmail.com/enca&HL=3DMarket_MSNIS_Taglines
> Start enjoying all the benefits of MSN=AE Premium right now and get the
> first two months FREE*.
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by BEA Weblogic Workshop
> FREE Java Enterprise J2EE developer tools!
> Get your free copy of BEA WebLogic Workshop 8.1 today.
> http://ads.osdn.com/?ad_id=3D5047&alloc_id=3D10808&op=3Dclick
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|