What part of the C++ IO streams does the \\r
to \\r\\n
conversion? Is it the stream_buf
itself or is it part of the internal to external encoding conversion by codecvt
facet?
UPDATE 1
You all say that it is done in streambuf/filebuf. Ok. But how does this arrangement deal with, eg, external encodings like UTF-16? Then it seems that the file has to be opened with ios::binary
flag which disables the translation.
This conversion is not (usually) performed by stream, streambuf, or facet. It is the responsibility the C library code (eg fputc()
) that is called by streambuf's overflow()
and underflow()
.
If you need it for some reason (eg when implementing a dos2unix routine), there's a handy example in boost.iostreams.
EDIT: std::filebuf
only supports multibyte encodings for text files, eg UTF-8 or GB18030 or whatever the locale uses. A UTF-16 file would have to be opened in binary mode, as a plain byte stream (which can be interpreted as UTF-16 with C++11's codecvt facilities), and yes the line endings would not get converted.
IFAIR在streambuf实现中完成, codecvt
只处理区域设置表示细节。
它由std :: filebuf执行,如果它是在没有ios :: binary标志的情况下打开的话。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.