64,649
社区成员
发帖
与我相关
我的任务
分享
7 int main(int argc,char** argv){
8 std::string str = "qilov我e爱你中国";
9 wchar_t w_char[10000];
10
11 setlocale(LC_ALL,"zh_CN.utf8");
12 mbstowcs(w_char,str.c_str(),str.size());
13 std::wstring w_str(w_char);
14
15 //w_str.erase(w_str.begin()+8,w_str.end());
16
17 std::wcout<< w_str.size() <<std::endl;
18 std::wcout<< w_str <<std::endl;
19
20 wcstombs(&str[0],w_str.c_str(),w_str.size() * 3);
21
22 std::cout << str <<std::endl;
23
24 return EXIT_SUCCESS;
25 }
18 std::wcout<< w_str <<std::endl
22 std::cout << str <<std::endl;
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
int i;
char *pmbbuf = (char *)malloc( MB_CUR_MAX );
wchar_t *pwchello = L"Hello, world.";
printf( "Convert wide-character string:\n" );
i = wcstombs( pmbbuf, pwchello, MB_CUR_MAX );
printf( "\tCharacters converted: %u\n", i );
printf( "\tMultibyte character: %s\n\n", pmbbuf );
}
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
int i;
char *pmbnull = NULL;
char *pmbhello = (char *)malloc( MB_CUR_MAX );
wchar_t *pwchello = L"Hi";
wchar_t *pwc = (wchar_t *)malloc( sizeof( wchar_t ));
printf( "Convert to multibyte string:\n" );
i = wcstombs( pmbhello, pwchello, MB_CUR_MAX );
printf( "\tCharacters converted: %u\n", i );
printf( "\tHex value of first" );
printf( " multibyte character: %#.4x\n\n", pmbhello );
printf( "Convert back to wide-character string:\n" );
i = mbstowcs( pwc, pmbhello, MB_CUR_MAX );
printf( "\tCharacters converted: %u\n", i );
printf( "\tHex value of first" );
printf( " wide character: %#.4x\n\n", pwc );
}