Edit: I had a stupid bug in code and fixed it, so now things are clear Ho . First, the result when doing some piping in the program. Second, I have typed [enter] [enter] [enter] and enter [enter] [enter]. Support Third, I have typed "asdf" for each I think you have reversed your status here:
$ echo 'asdf' | ./seektest stdin does not support fseek () c == s std :: cin does not support seekg (second) fail to read std :: cin! C ==? Std :: cin fail to read second! C ==?
$ ./seektest a stdin Previous () S c == s std :: cin seekg () Supports DC == DC == < / Pre>
getc /
get () call.
$ ./seektest asdf stdin supports () Asdf c supports == one std :: cin seekg ()
# include & lt; Iostream & gt; # Include & lt; Cstdio & gt; Try int int (int argc, char ** argv) {/ cstdio} int x = fgetc (stdin); If (x & lt; 0) {FPrintf (steder, "Studen first read failed!"); } Int res = fseek (stdin, -1, SEEK_CUR); If (! Res) {fprintf (stdout, "stdin supports fseek). \" "); } And {fprintf (stdout does not support "stdin fseek ()) \ n"); } X = fgetc (stdin); If (x & lt; 0) {FPrintoff (stadder, "failed in second studine! \ N"); } Four c = x; Fprintf (stdout, "c ==% c \ n", c); Try Iostream / X = std :: cin.get (); If (std :: cin.fail ()) {fprintf (stderr, "first std :: cin read failed! \ N"); } Std :: cin.seekg (-1, std :: ios :: cur); If (std :: cin.fail ()) {fprintf (stdout does not support "std :: cin seekg ()", \ n "); } And {fprintf (stdout, "std :: cin seekg (). \ N"); } C = std :: cin.get (); If (std :: cin.fail ()) {fprintf (stderr, "second read studs :: cine failure! \ N"); } Fprintf (stdout, "c ==% c \ n", c); C = std :: cin.get (); If (std :: cin.fail ()) {fprintf (stderr, "second read studs :: cine failure! \ N"); } Fprintf (stdout, "c ==% c \ n", c); Return 0; }
if {std :: cin.fail ()} {fprintf (stdout supports "std :: cin seekg (). \ N"); } And {fprintf (stdout, "std :: cin seekg () does not support. \ N"); }
std :: cin "supports
seekg () " if it fail ?
Comments
Post a Comment