I use C ++ streams to read into a bunch of files in a directory, and then write them to another directory. Since these files can be of different types, I use the common ios :: binary flag when reading / writing these files. Sample code below:
std::fstream inf( "ex.txt", std::ios::in | std::ios::binary);
char c;
while( inf >> c ) {
}
The problem is that in the case of files containing text, the line breaks in these text files are not written to the output file.
Edit: Or at least they don't look like when a new file is opened, there is only one continuous line of characters.
Change again: the problem (continuous line) persists even when the read / write is in text mode.
So, I was wondering if there is a way to check if the file is in text or binary format, and then read / write it correctly. Else, is there a way to keep the end of line characters even when opening a file in binary format?
Edit: I am using the g ++ 4.8.2 compiler
source
share