0

I'm using mostly wstring and wide characters in my application. I'm saving data to files using ofstream and large amount of conversions in my code.

I need my save files to be easily editable by hand, therefore I'd like to keep current file encoding. Now I'm trying to make my code cleanier and get rid of these conversions, so I'm thinking about moving to wofstream and wifstream.

If I use wofstream will files have same (current) encoding or will files be encoded in UTF-32 ( UTF-16 for Windows ) ?

ST3
  • 8,826
  • 3
  • 68
  • 92
kravemir
  • 10,636
  • 17
  • 64
  • 111
  • On windows: the encoding will be UTF-16 with wofstream and the system narrow encoding for your locale with ofstream. – indeterminately sequenced Apr 17 '13 at 18:33
  • Why are you worried about the encoding? If the files were human readable before, they will still be readable with this change. Do you mean editing the binary contents of the file? – indeterminately sequenced Apr 17 '13 at 18:34
  • I mean If there won't be any coruption of data by it's editing and if same file will be readable in both Linux and Windows environment like it's for now – kravemir Apr 17 '13 at 18:38
  • There will be no corruption of data provided you don't write a file with wofstream & read it with ifstream & vice versa. If you want to do so you will probably have to set the stream [locale](http://msdn.microsoft.com/en-us/library/36h875af.aspx). manual editing in a text editor will not corrupt the file. – indeterminately sequenced Apr 17 '13 at 18:47
  • Ah, didn't see the linux & windows part. Yes it will be readable & editable on both os's. Most text editors allow you to manually specify encoding if they can't auto-detect it. To help in auto-detection you can write a [BOM](http://en.wikipedia.org/wiki/Byte_order_mark "Byte Order Marker") as the first bytes of your file. – indeterminately sequenced Apr 17 '13 at 19:25

0 Answers0