Confused about C++'s std::wstring, UTF-16, UTF-8 and displaying strings in a windows GUI

后端 未结 5 1700
长发绾君心
长发绾君心 2020-12-28 17:21

I\'m working on a english only C++ program for Windows where we were told \"always use std::wstring\", but it seems like nobody on the team really has much of an understandi

5条回答
  •  情深已故
    2020-12-28 17:29

    Even if you say you only have English in your data, you're probably wrong. Since we're in a global world now, names/addresses/etc have foreign characters. OK, I do not know what type of data you have, but generally I would say build your application to support UNICODE for both storing data and displaying data to user. That would suggest using XML with UTF-8 for storing and UNICODE versions of Windows calls when you do GUI. And since Windows GUI uses UTF-16, where each token is 16-bit, I would suggest storing the data in the application in an 16-bit wide string. And I would guess your compiler for windows would have std::wstring as 16-bit for just this purpose.

    So then you have to do a lot of conversion between UTF-16 and UTF-8. Do that with some existing library, like for instance ICU.

提交回复
热议问题