这个得到的line字符串只要是中文就是乱码 该怎么弄呀?代码程序不是我写的extern "C" {JNIEXPORT jstring JNICALL Java_TXT_TextDemo_GetPath(JNIEnv * v, jclass TestNative){jstring r = NULL;int i = 0;char *c = new char[100];char line[260];char *utf;LPWSTR p = GetCommandLine();wchar_t *cur = p;char *des = line;unsigned int x = 0;// convert wchar_t* to char*// 注意这个函数不支持中文,因为没有将GBK编码转UTF,网上找GBKtoUTF8for(;*cur!=0;cur++) {x = (unsigned int)*cur;*des = (char)(x%256); des++;if(x>=256) {*des = (char)(x/256); des++;}}*des = 0;r=v->NewStringUTF(line);//r = v->NewStringreturn r;}} // end of extern#endif
1 回答
精慕HU
TA贡献1845条经验 获得超8个赞
// 注意这个函数不支持中文,因为没有将GBK编码转UTF,网上找GBKtoUTF8
string GBKToUTF8(const std::string& strGBK)
{
string strOutUTF8 = "";
WCHAR * str1;
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
str1 = new WCHAR[n];
MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, str1, n);
n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL);
char * str2 = new char[n];
WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);
strOutUTF8 = str2;
delete[]str1;
str1 = NULL;
delete[]str2;
str2 = NULL;
return strOutUTF8;
}
- 1 回答
- 0 关注
- 641 浏览
添加回答
举报
0/150
提交
取消