#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main(){
setlocale(LC_ALL, "zh_CN.utf-8"); //设置编码格式
string name_en = "路名";
int len_w = mbstowcs(NULL, name_en.c_str(), 0);
cout<<len_w<<endl;
if (len_w > 0) {
unsigned int buffer_size = static_cast<unsigned int>(len_w + 1) * sizeof(wchar_t);
wchar_t* str_w = static_cast<wchar_t *>(malloc(buffer_size));
if (NULL == str_w) {
return false;
}
mbstowcs(str_w, name_en.c_str(), len_w);
for (int i = 0; i < len_w; ++i) {
if (str_w[i] >= 19968 && str_w[i] <= 40869) {
cout<<"汉字"<<endl;
break;
}
}
free(str_w);
}
return 0;
}
#include<stdlib.h>
#include<string.h>
using namespace std;
int main(){
setlocale(LC_ALL, "zh_CN.utf-8"); //设置编码格式
string name_en = "路名";
int len_w = mbstowcs(NULL, name_en.c_str(), 0);
cout<<len_w<<endl;
if (len_w > 0) {
unsigned int buffer_size = static_cast<unsigned int>(len_w + 1) * sizeof(wchar_t);
wchar_t* str_w = static_cast<wchar_t *>(malloc(buffer_size));
if (NULL == str_w) {
return false;
}
mbstowcs(str_w, name_en.c_str(), len_w);
for (int i = 0; i < len_w; ++i) {
if (str_w[i] >= 19968 && str_w[i] <= 40869) {
cout<<"汉字"<<endl;
break;
}
}
free(str_w);
}
return 0;
}