Is there an analogue of the function cin.peek () in C? Or do you have to read the symbol from the stream in C, and then return it?
1 answer
There is no analog. You need to write yourself:
/* return the next character from stdin without consuming it */ int peekchar(void) { int c = getchar(); if (c != EOF) ungetc(c, stdin); /* puts it back */ return c; } http://www.cs.yale.edu/homes/aspnes/pinewiki/C(2f)InputOutput.html
int fpeek(FILE *stream){ int c = fgetc(stream); ungetc(c, stream); return c; } https://stackoverflow.com/questions/2082743/c-equivalent-to-fstreams-peek
|