Skip EOF while reading a file in C++
Asked Answered
S

1

5

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?

Sunsunbaked answered 18/10, 2012 at 21:17 Comment(0)
A
7

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);
Astonishment answered 18/10, 2012 at 21:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.