2016-04-11 11 views
0

符号なしの値をwchar_t配列にコピーしたいと思います。 と使用して、このwchar_tにunsigned longを変換してください

unsigned long lValue = <value>//value 

wchar_t wszBuffer[256] = L""; 
::swprintf_s(wszBuffer, _countof(wszBuffer), wszFormat, lValue); 

それは、このための2147483647 いただきましたソリューションよりも大きいlong値では動作しませんか?

+0

ために、次の値であり、どのような'wszFormat'?私は ''%lu ''を期待しています。 – chux

+0

ありがとうございます。これは間違いでした。私は%dを使用していました。 – Sana

答えて

0

考えてみましょうwchar_tは2 16bit intとしてUTF-16形式で保存されます。 あなたがしなければならない限り使用しません。以下の構造は、任意のチャーターを単一のuint32_t(C++の32ビット整数)に格納します。 しかし、あなたはunsigned long型(64ビット整数)の配列が必要な場合は、 私はこのようなベクターを用いて1を作成します。

std::vector<uint64_t> array; 

が32ビット以下

full file location: 
https://github.com/NashBean/iBS_LIB/blob/master/iBS_Header.h 

//----------------------------------------------- 
//uchar = uint made to hold any char of the world 
//----------------------------------------------- 
struct uchar 
{ 
    uchar():value(0){}; 
    uchar(int v):value((uint32_t)v){}; 
    uchar(long v):value((uint32_t)v){}; 
    uchar(uint32_t v):value(v){}; 
    uchar(uint v):value(v.get()){}; 
    uchar(char v):value((uint32_t)v){}; 
    uchar(uchar const &v):value(v.value){}; 
    uchar(wchar_t wch):value(decode(wch)){}; 

    uchar& operator=(int unicode){ 
    set((uint32_t)unicode); 
return *this; }; 
    uchar& operator=(uint32_t unicode){ set(unicode); 
return *this; }; 
    uchar& operator=(uint unicode) { set(unicode.get()); 
return *this; }; 
    uchar& operator=(char ch) { set((uint32_t)ch); return *this; }; 
    uchar& operator=(uchar uch) { set(uch.get()); return *this; }; 
    uchar& operator=(wchar_t wch) { set(decode(wch).get()); 
return *this; };// use of Uchar.h 

    bool operator==(int i) { return (value == i); }; 
    bool operator==(uint32_t unicode) { return (value == unicode); }; 
    bool operator==(uint unicode) { return (value == unicode); }; 
    bool operator==(char c) { return (value == c); }; 
    bool operator==(uchar uch) { return (value == uch.value); }; 

    uint32_t get() { return value.get(); }; 
    void set(uint32_t v) { value = v; }; 

private:  
    uint value; 
}; 
+0

このコードは質問に答えるかもしれませんが、問題の解決方法および/または理由を説明する追加の文脈を提供すると、回答の長期的価値が向上します。 – cpburnz

関連する問題