hi i dont know how and why use the .clear() function
ie:
please any help about the when and why to use it?Code:file.clear();//if file is a fstream or cin.clear();//working with cin
thanks for any help
hi i dont know how and why use the .clear() function
ie:
please any help about the when and why to use it?Code:file.clear();//if file is a fstream or cin.clear();//working with cin
thanks for any help
you'd want to use it if you know there is garabage in you streams eg.
someone inputs a letter instead of a number.
Woop?
http://cplusplus.com/ref/iostream/ios/clear.html
I use it the most when I read EOF yet need to loop back and read again. At that point i have to call clear() that will allow me to read, otherwise it won't.
source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense
ok thanks for reply
expanding on what alphaoide said... it resets (clears) all the flags that have been set for that stream. for example, to set cout to only display two decimal points on floats:
and if you wroteCode:cout.setf(ios::fixed); cout.setf(ios::showpoint); cout<<setprecision(2);it would clear all the flags you just set.Code:cout.clear()
note: code not tested... I haven't used it in a long time and am not sure it works... you can try if you like... it would probably be good practice with flags... and here's a list of flags and their manipulators: http://cppreference.com/cppio_flags.html
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT