Skip EOF while reading a file in C ++

Whenever I come across the replacement symbol http://en.wikipedia.org/wiki/Substitute_character when reading a file in C ++ using getline (), it is interpreted as EOF, so I cannot go forward with my reading so that get a file of all contents. So my question is: how can I skip the replacement characters and read the contents of the file to the "real" EOF?

+4
source share
1 answer

Open the file in binary mode instead of text mode. If you use fopen , open it in one of the "b" modes, for example. "rb" . If you are using a C ++ ifstream , open it using the ios::binary flag.

For instance:

 // C method FILE *f = fopen("filename", "rb"); // C++ method std::ifstream f("filename", std::ios::in | std::ios::binary); 
+6
source

Source: https://habr.com/ru/post/1440656/


All Articles