Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道在 C++ 中,您可以使用以下命令查看下一个字符:in.peek();。
in.peek();
当试图“偷看”C 中文件的下一个字符时,我将如何处理这个问题?
fgetc + ungetc。也许是这样的:
int fpeek(FILE *stream) { int c; c = fgetc(stream); ungetc(c, stream); return c; }
您可以使用 agetc后跟ungetc
getc
ungetc
你需要自己实现它。使用fread读取下一个字符并使用fseek回到读取之前的位置
编辑:
int fsneaky(FILE *stream, int8_t *pBuff, int sz) { sz = fread(pBuff, 1, sz, stream) fseek(pFile, -sz, SEEK_CUR); return(sz); }