2016-04-11 29 views
0

İmzasız bir değeri wchar_t dizisine kopyalamak istiyorum. ve kullanarak buunsigned long to wchar_t

unsigned long lValue = <value>//value 

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

bunun için 2147483647 nedir çözümü daha büyük uzun değerler için çalışmıyor?

+0

için aşağıdaki değeri nedir 'wszFormat'? "% Lu" diyebilirim. – chux

+0

Teşekkür ederim ... bu bir hataydı. % D kullanıyordum. – Sana

cevap

0

wchar_t öğesinin UTF-16 biçimi olarak 2 16bit int olarak kaydedildiğini düşünün. Yapmanız gerekmedikçe onu kullanmayın. Aşağıdaki yapı, herhangi bir tüzüğü tek bir uint32_t (C++ 'da 32 bit tam sayı) içinde depolar. Ama imzasız uzun (64 bitlik tamsayı) dizi gerekiyorsa, Böyle bir vektör ile bir yaratacak:

std::vector<uint64_t> array; 

32 bit ya da daha az

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

Bu kod soruyu yanıtlarken, sorunun nasıl ve/veya neden çözüldüğüne ilişkin ek bağlam sağlayarak yanıtın uzun vadeli değerini artıracaktır. – cpburnz

İlgili konular