• <tfoot id='eOkg8'></tfoot>
      <legend id='eOkg8'><style id='eOkg8'><dir id='eOkg8'><q id='eOkg8'></q></dir></style></legend>

        <bdo id='eOkg8'></bdo><ul id='eOkg8'></ul>

    1. <small id='eOkg8'></small><noframes id='eOkg8'>

      <i id='eOkg8'><tr id='eOkg8'><dt id='eOkg8'><q id='eOkg8'><span id='eOkg8'><b id='eOkg8'><form id='eOkg8'><ins id='eOkg8'></ins><ul id='eOkg8'></ul><sub id='eOkg8'></sub></form><legend id='eOkg8'></legend><bdo id='eOkg8'><pre id='eOkg8'><center id='eOkg8'></center></pre></bdo></b><th id='eOkg8'></th></span></q></dt></tr></i><div id='eOkg8'><tfoot id='eOkg8'></tfoot><dl id='eOkg8'><fieldset id='eOkg8'></fieldset></dl></div>

        如何将 char* 转换为 wchar_t*?

        时间:2023-08-02
        <tfoot id='yRmiR'></tfoot>
        <legend id='yRmiR'><style id='yRmiR'><dir id='yRmiR'><q id='yRmiR'></q></dir></style></legend>
        <i id='yRmiR'><tr id='yRmiR'><dt id='yRmiR'><q id='yRmiR'><span id='yRmiR'><b id='yRmiR'><form id='yRmiR'><ins id='yRmiR'></ins><ul id='yRmiR'></ul><sub id='yRmiR'></sub></form><legend id='yRmiR'></legend><bdo id='yRmiR'><pre id='yRmiR'><center id='yRmiR'></center></pre></bdo></b><th id='yRmiR'></th></span></q></dt></tr></i><div id='yRmiR'><tfoot id='yRmiR'></tfoot><dl id='yRmiR'><fieldset id='yRmiR'></fieldset></dl></div>

          <small id='yRmiR'></small><noframes id='yRmiR'>

                <tbody id='yRmiR'></tbody>

                • <bdo id='yRmiR'></bdo><ul id='yRmiR'></ul>
                  本文介绍了如何将 char* 转换为 wchar_t*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试过实现这样的功能,但不幸的是它不起作用:

                  I've tried implementing a function like this, but unfortunately it doesn't work:

                  const wchar_t *GetWC(const char *c)
                  {
                      const size_t cSize = strlen(c)+1;
                      wchar_t wc[cSize];
                      mbstowcs (wc, c, cSize);
                  
                      return wc;
                  }
                  

                  我的主要目标是能够在 Unicode 应用程序中集成普通字符字符串.非常感谢你们提供的任何建议.

                  My main goal here is to be able to integrate normal char strings in a Unicode application. Any advice you guys can offer is greatly appreciated.

                  推荐答案

                  使用 std::wstring 而不是 C99 变长数组.当前标准保证 std::basic_string 的连续缓冲区.例如,

                  Use a std::wstring instead of a C99 variable length array. The current standard guarantees a contiguous buffer for std::basic_string. E.g.,

                  std::wstring wc( cSize, L'#' );
                  mbstowcs( &wc[0], c, cSize );
                  

                  C++ 不支持 C99 可变长度数组,因此如果您将代码编译为纯 C++,它甚至无法编译.

                  C++ does not support C99 variable length arrays, and so if you compiled your code as pure C++, it would not even compile.

                  随着更改,您的函数返回类型也应该是 std::wstring.

                  With that change your function return type should also be std::wstring.

                  记得在main中设置相关的locale.

                  Remember to set relevant locale in main.

                  例如,setlocale( LC_ALL, "" ).

                  这篇关于如何将 char* 转换为 wchar_t*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 DirectX 捕获屏幕 下一篇:如何获取当前正在执行的代码的 HMODULE?

                  相关文章

                  最新文章

                  1. <small id='vnpPI'></small><noframes id='vnpPI'>

                  2. <i id='vnpPI'><tr id='vnpPI'><dt id='vnpPI'><q id='vnpPI'><span id='vnpPI'><b id='vnpPI'><form id='vnpPI'><ins id='vnpPI'></ins><ul id='vnpPI'></ul><sub id='vnpPI'></sub></form><legend id='vnpPI'></legend><bdo id='vnpPI'><pre id='vnpPI'><center id='vnpPI'></center></pre></bdo></b><th id='vnpPI'></th></span></q></dt></tr></i><div id='vnpPI'><tfoot id='vnpPI'></tfoot><dl id='vnpPI'><fieldset id='vnpPI'></fieldset></dl></div>
                      • <bdo id='vnpPI'></bdo><ul id='vnpPI'></ul>
                      <tfoot id='vnpPI'></tfoot>
                      <legend id='vnpPI'><style id='vnpPI'><dir id='vnpPI'><q id='vnpPI'></q></dir></style></legend>