1

My work uses windows wstring for everything. I wanted to run something like less on a logfile but found it includes spaces around every character.

I've messed with codetables and other things to make my terminal "see" utf-16, but haven't gotten anywhere. Can this even be done?

2c2c
  • 4,694
  • 7
  • 22
  • 33
  • Why not write data to your log file using UTF-8 instead of UTF-16? You can still work with UTF-16 strings in your code, just convert them whenever they exit your app. – Remy Lebeau Aug 24 '18 at 23:52
  • Also see: https://stackoverflow.com/questions/4053918/how-to-portably-write-stdwstring-to-file – Will Bickford Aug 25 '18 at 02:20
  • Might also see this SO question, it's specific to grep but most of the advice still applies: https://stackoverflow.com/questions/3752913/grepping-binary-files-and-utf16 – MrEricSir Aug 25 '18 at 05:33

1 Answers1

1

@2c2c I believe you know that wstring treats avery character as double byte, where every characher is present as two hex codes. Do you have any characters, where second byte is not 0x00? If not, then looks like less converts them to spaces. In this case, you could convert output by using WideCharToMultiByte() function.

Valeca
  • 122
  • 8