SAMPFUNCS and encoding text

Статус
В этой теме нельзя размещать новые ответы.

seek1

Известный
Автор темы
21
0
I am working on something using sampfuns and i have a function which parameters takes string example:


void CALLBACK settext(std::string params)
{
}


/settext Да

the word "Да" show in very weird characters.. can you help me to display it in correct way
 

itsLegend

Фонд борьбы за жуков 🐞
Администратор
2,695
1,448
You can check it on simple console application with multibyte encoding?
 

seek1

Известный
Автор темы
21
0
C++:
size_t StrToWstr(wstring& aDst, const string& aSrc)
{
    size_t length;
    length = mbstowcs(NULL, aSrc.c_str(), 0);
    if (length != static_cast<size_t>(-1)) {
        wchar_t *buffer = new wchar_t[length + 1];
        length = mbstowcs(buffer, aSrc.c_str(), length);
        buffer[length] = L'\0';
        aDst.assign(buffer);
        delete[] buffer;
    }
    return length;
}


void settext(std::string params) {
    std::locale::global(std::locale("Russian"));
    wstring ws;
    StrToWstr(ws, params); // ws contain correct word "Да"
  
    char Buff[512];
    sprintf(Buff, "%ws", ws.c_str()); // Buff is contain weird characters

}

int main()
{

    settext("Да");

    return 0;
}

i convert the string to widestring to be set correctly and yeah the ws contain the word without any encoding issue, but i am wondering why when i try to write it to the Buff it shows there strange characters!
 
Последнее редактирование:

Losyash1337

Новичок
16
16
C++:
std::string str = "Дыа";
std::wstring wstr (str.begin(), str.end()); // cpp style
C++:
// Windows style
char *a="Дыа";
wchar_t *b=new wchar_t[10];
CharToOem(a,b);   // CHAR* to WCHAR*
OemToChar(b, a);  // WCHAR* to CHAR*
 
Последнее редактирование:
Статус
В этой теме нельзя размещать новые ответы.