say I have a text file (assuming it's stored in ASCII encoding which is 1 byte).
Can I open it as a binary file and when I read each byte, I cast it into a char? Or read a chunk of bytes and cast it into a c-string or string object?
reason I want to do this is to take advantage of the random access property of binary files
@Duoas,
Are CR and LF Carriage Return and LineFeed (which would be '\r' and '\n' respectively)?
I never got why windows and DOS used both...
@unregistered,
I think it's safe to assume that Duoas was saying you can use random access on text files if you open them in binary mode; but you'll have to handle different forms of newline yourself, because different operating systems format text files in different ways, like Duoas said.
You could probably stand to do that with the preprocessor:
1 2 3 4 5 6 7
#if defined _WIN32
// use CR LF
#elif defined POSIX
// use LF
#else
// use CR
#endif