一行文本中既有英文字符又有汉字,请问怎么识别汉字?

解决方案 »

  1.   

    #include <tchar.h>
    #include "string"
    using namespace std;
    #include "windows.h"int main(int argc, char* argv[])
    {
    char *str="abc中文汉字def";
    char *p=str,*p1;
    unsigned short ch;
    //str2按字遍历字符串
    string str2="";
    while(strcmp(p,"")!=0)
    {
    str2="";
    p1=CharNextExA(936,p,0);
    int i=p1-p;
    if(i==1)
    {
    ch=(unsigned char)*p;
    str2+=*p;
    }else if(i==2)
    {
    ch=(*p)*256+*(p+1);
    str2+=*p;
    str2+=*(p+1);
    }
    p=p1;
    // p是剩下的字符串,ch是一个字的值
    }
    return 0;
    }