How can I use wstring in Linux API?

I want to develop an application on Linux. I want to use wstring beacuse, my application must support unicode, and I don't want to use UTF-8 strings.

On Windows, using wstring is very simple. beacuse any ANSI API is unicode. for example, there are two CreateProcess APIs, the first API is CreateProcessA, and the second API is CreateProcessW.

wstring app = L"C:\\test.exe";
CreateProcess
(
  app.c_str(), // EASY!
  ....
);

But it seems that working with wstring on Linux is complicated! for example, there is an API on Linux called parport_open (This is just an example).

and I don’t know how to send my wstring to this API (or APIs like parport_open that take a string parameter).

wstring name = L"myname";
parport_open
(
  0, // or a valid number. It is not important in this question.
  name.c_str(), // Error: because type of this parameter is char* not wchat_t*
  ....
);

My question is: how can I use wstring in Linux API?

Note . I do not want to use UTF-8 strings.

thank

+3
2

API Linux ( ) UTF-8 1. . .

wchar_t (, , wstring) Windows , Unicode 65536 (.. wchar_t UCS-2), , 16- Windows wchar_t UTF-16 1 wchar_t= 1 - , UTF-8. IMHO Linux . ( UTF-16 Windows Java )

, string, wstring , , Unicode. , wxString wxWidgets UTF-8, .


  • , , ​​ -, .. (NUL-terminated?) ( , " " , UTF- 16 ). , , , , Linux UTF-8 ( ).
+2

UTF-8.

, , , API. Linux , UTF-8. , , , , , char*. string, wstring.

0

Source: https://habr.com/ru/post/1683627/


All Articles