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?
Skip EOF while reading a file in C++
Open the file in binary mode instead of text mode. If you're using fopen
, make open it in one of the "b"
modes, e.g. "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);
© 2022 - 2024 — McMap. All rights reserved.