mbtowc
は、1文字のみを変換します。 mbstowcs
を使用しましたか?
通常、この関数を2回呼び出します。必要なバッファサイズを取得する最初の、そして第二には、実際にそれを変換する:
#include <cstdlib> // for mbstowcs
const char* mbs = "c:\\user";
size_t requiredSize = ::mbstowcs(NULL, mbs, 0);
wchar_t* wcs = new wchar_t[requiredSize + 1];
if(::mbstowcs(wcs, mbs, requiredSize + 1) != (size_t)(-1))
{
// Do what's needed with the wcs string
}
delete[] wcs;
あなたはむしろmbstowcs_s
(理由は非推奨の警告を)使用する場合は、この操作を行います。
#include <cstdlib> // also for mbstowcs_s
const char* mbs = "c:\\user";
size_t requiredSize = 0;
::mbstowcs_s(&requiredSize, NULL, 0, mbs, 0);
wchar_t* wcs = new wchar_t[requiredSize + 1];
::mbstowcs_s(&requiredSize, wcs, requiredSize + 1, mbs, requiredSize);
if(requiredSize != 0)
{
// Do what's needed with the wcs string
}
delete[] wcs;
はあなたのことを確認してくださいsetlocale()経由で、またはロケール引数を取る(mbstowcs_l()
またはmbstowcs_s_l()
など)のバージョンを使用してロケールの問題を処理します。
+1は - あまりにも壊れたリンクを修正:) –
@Billy ONeal:感謝を。感謝します。 :-) –
'delete [] wcs;' –