Streams, stream_bufs, fax codecvt and translate \ n to \ r \ n

What part of the IO C ++ threads does the conversion \rto \r\n? Is it itself stream_bufor is it part of the conversion of internal coding to an external format codecvt?

UPDATE 1

You all say this is done in streambuf / filebuf. OK. But how is this related to, for example, external encodings such as UTF-16? Then it seems that the file should be open with a flag ios::binarythat disables translation.

+5
source share
3 answers

This conversion is not performed (usually) with stream, streambuf or facet. It is responsible for the C library code (for example, fputc()) that is called by streambuf overflow()and underflow().

If you need this for any reason (for example, when implementing the dos2unix procedure), there is a convenient example in boost.iostreams.

EDIT: std::filebufonly supports multibyte encodings for text files such as UTF-8 or GB18030, or whatever language it uses. A UTF-16 file should be opened in binary mode, as a simple stream of bytes (which can be interpreted as UTF-16 with C ++ 11 codecvt tools), and yes, line endings will not be converted.

+2
source

IFAIR, streambuf, codecvt .

+1

std:: filebuf, ios:: .

+1

All Articles