mac版:
//
// main.m
// test
//
// Created by haidrgon on 2018/12/20.
// Copyright © 2018 haidrgon. All rights reserved.
//
#import <Foundation/Foundation.h>
#include<iostream>
#include <string>
#include <stdlib.h>
#import<cwchar>
#import<wchar.h>
using namespace std;
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
wchar_t* temp=L"abc123你我他";
wstring wstr = temp;
wprintf(L"%s\n", wstr.c_str());
// wcout.imbue(locale("chs"));
wcout<<wstr<<endl;
NSData *data = [NSData dataWithBytes:wstr.data() length:sizeof(wchar_t) * wstr.size()];
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF32LittleEndianStringEncoding];
NSLog(@"str %@", str);
NSLog(@"Hello, World!");
cout<<[str UTF8String]<<endl;
}
return 0;
}
wstring问题
linux版
#include<iostream>
#include<string>
#include<locale>
using namespace std;
int main()
{
wstring wstr=L"世界你好!";
locale loc("zh_CN.UTF-8");
locale::global(loc);
wcout<<wstr<<endl;
return 0;
}
wstring问题
win版:
printf("argv[1]%s\n", argv[1]);
int len = MultiByteToWideChar(CP_ACP, 0, argv[1], strlen(argv[1]), NULL, 0);
m_wchar = new wchar_t[len + 1];
char2wchar(argv[1], m_wchar);
setlocale(LC_ALL, "chs");//#include <locale.h>
wprintf(L"argv[1]%s\n", wstring(m_wchar).c_str());
wprintf(L"argv[1]%s\n",m_wchar);
printf("argv[1]%ws\n", m_wchar);
wstring问题
©著作权归作者所有:来自51CTO博客作者土匪猿的原创作品,如需转载,请注明出处,否则将追究法律责任
共同学习,写下你的评论
评论加载中...
作者其他优质文章