C++ fstream如何实现从文件末尾向文件开头读?

void read_ch( fstream &File){ char ch; while ( true ) { File.get(ch); cout<<ch; File.seekg( -2, ios::cur ); }}这样好像读到换行符就不能再往前移动了,请教大牛.
2026年09月28日 20:10
有1个网友回答
网友(1):

先移动到文件尾: File.seekg (0, ios::end);
再开始读。
ios::cur 是当前位置。