TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JASON HULME
from: THOMAS MAEDER
date: 1997-05-23 09:29:00
subject: cin errors

JH> if an char value is inputed into a cin << input, where input is defi
JH> a float my program goes "crazy" All inputs after the cin .. are not
JH> accepted. Is there a way to get around this? I plan to have a window
JH> and say "Invalid amount please redo"
JH> I have tried:
JH> if (input!=float) cout <<"invalid";
JH>                        ...but the program still exectued the same.
float input;
if (cin << input)
    // do your stuff here
else
    cout << "invalid";
should work (streams have implicit conversion to a boolean  type  that
can be used like this).
If you are programming under Windows 95, there might also be a problem
with floating point stream I/O when some older version of  the  System
Agent is running.
Thomas
---
 þ MM 1.0 #0113 þ I just got a new car for my girlfriend....Great trade...
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.