简体   繁体   中英

Skip EOF while reading a file in C++

Whenever I encounter a substitute character http://en.wikipedia.org/wiki/Substitute_character while reading a file in C++ using getline(), it is interpreted as a EOF so I cannot advance with my reading in order to get the file entire content. So my question is, how can I skip the substitute characters and read the content of the file until the "real" EOF?

Open the file in binary mode instead of text mode. If you're using fopen , make open it in one of the "b" modes, eg "rb" . If you're using a C++ ifstream object, open it with the ios::binary flag.

For example:

// C method
FILE *f = fopen("filename", "rb");

// C++ method
std::ifstream f("filename", std::ios::in | std::ios::binary);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM