Sunday 15 February 2015

Writing binary files using C++: does the default locale matter? -


itemprop = "text">

I have a code that uses binary files using fstream with binary flag set and read without using formatted I / O functions and I write works correctly on all the systems I have ever used (bits are actually expected in the file), but they are basically all U.S.. Are english I am thinking of the possibility of being modified by codecvv on different systems for these bytes.

It seems like the formatted I / O using standard using spreadsheets / sgetc in the virtual world. These will lead to overflow or underflow functions in Streambuff, and it looks like these leads for things that go through some codecvt (e.g., see 27.8.1.4.3 in C ++ standard). The build of this codecvt for the basic file is specified in 27.8.1.1.5. From this, it seems that the result will depend on the basic file that returns the default_filebuf.tlock ().

So, my question is, can I assume that using a character array made through a system on any system? Verbally using any ifstream.read on any other system, even if any locale configuration is using any person on their system? I will make the following assumptions:

  1. The program is using default locale (i.e., the program locale setting itself is not changing).
  2. The system is both CHAR_BIT 8, store files in the form of a single bit order, octets, etc. within each byte.
  3. The binary flag is set in the stream objects.
  4. We do not have to worry about any endless differences at this level. If any byte is interpreted as a multi-byte value in the array, then the final conversion will be handled as necessary.

If the default locale pass is not guaranteed, through this content attached to some system configuration (I do not know, Arabic or something else), write binary files using C ++ What is the best way?

This should be fine on Windows, but on other OS you can get a line end (such as security) Should also be seen. The default C / C ++ locale is "C" which is not depending on the system locale.

It is not guaranteed as you know the C / C + compiler and their target machines are very different. If you keep all those beliefs, then you are waiting for troubles. There is a negligible overhead to change the locale, unless you try to make it hundreds of seconds per second.


No comments:

Post a Comment