
23.07.2017, 15:40
|
|
Новичок
Регистрация: 30.11.2013
Сообщений: 21
С нами:
6551760
Репутация:
51
|
|
C++:
Код:
size_t
StrToWstr
(
wstring
&
aDst
,
const
string
&
aSrc
)
{
size_t length
;
length
=
mbstowcs
(
NULL
,
aSrc
.
c_str
(
)
,
0
)
;
if
(
length
!=
static_cast
(
-
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!
|
|
|