C语言 C 相当于 fstream 的 peek
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2082743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C equivalent to fstream's peek
提问by Anthony
I know in C++, you're able to peek at the next character by using: in.peek();.
我知道在C ++中,你可以通过使用下一个字符偷看:in.peek();。
How would I go about this when trying to "peek" at the next character of a file in C?
尝试在 C 中“偷看”文件的下一个字符时,我将如何处理?
回答by ephemient
回答by Charles Ma
you'll need to implement it yourself. use freadto read the next character and fseekto go back to where you were before the read
你需要自己实现它。使用fread读取下一个字符,使用fseek返回读取前的位置
EDIT:
编辑:
int fsneaky(FILE *stream, int8_t *pBuff, int sz) {
sz = fread(pBuff, 1, sz, stream)
fseek(pFile, -sz, SEEK_CUR);
return(sz);
}

