为什么会出现错误C3851(通用字符名称不能在基本字符集中指定字符)? [英] Why do I get error C3851 (a universal-character-name cannot designate a character in the basic character set)?

查看:332
本文介绍了为什么会出现错误C3851(通用字符名称不能在基本字符集中指定字符)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在此处将一个示例空白去除器翻译成SO,以便在C ++-cli项目中运行。就智能感知而言,以下代码看起来不错:

I've been trying to translate an example whitespace remover from here on SO to run in a C++-cli project. The following looks fine as far as intellisense is concerned:

static String^ TrimAllWithInplaceCharArray(String^ str)
{
    unsigned int len = str->Length;
    array<wchar_t, 1>^ src = str->ToCharArray();
    int dstIdx = 0;
    for (unsigned int i = 0; i < len; i++) {
        wchar_t ch = src[i];
        switch (ch) {
            case L'\u0020': case L'\u00A0': case L'\u1680': case L'\u2000': case L'\u2001':
            case L'\u2002': case L'\u2003': case L'\u2004': case L'\u2005': case L'\u2006':
            case L'\u2007': case L'\u2008': case L'\u2009': case L'\u200A': case L'\u202F':
            case L'\u205F': case L'\u3000': case L'\u2028': case L'\u2029': case L'\u0009':
            case L'\u000A': case L'\u000B': case L'\u000C': case L'\u000D': case L'\u0085':
                continue;
            default:
                src[dstIdx++] = ch;
                break;
        }
    }
    return gcnew String(src, 0, dstIdx);
}

...但无法编译:

error C3851 : '\u0020' : a universal - character - name cannot designate a character in the basic character set
error C3850 : '\u0009' : a universal - character - name specifies an invalid character
error C3850 : '\u000A' : a universal - character - name specifies an invalid character
error C2196 : case value '63' already used
error C3850 : '\u000B' : a universal - character - name specifies an invalid character
error C2196 : case value '63' already used
error C3850 : '\u000C' : a universal - character - name specifies an invalid character
error C2196 : case value '63' already used
error C3850 : '\u000D' : a universal - character - name specifies an invalid character
error C2196 : case value '63' already used
error C3850 : '\u0085' : a universal - character - name specifies an invalid character
error C2196 : case value '63' already used

我错过了用某种方式表示数据类型或文字值吗?

Am I miss-representing a data type or the literal values in some way?

推荐答案

查看以下内容是否有效...

See if the following works...

static String^ TrimAllWithInplaceCharArray(String^ str)
{
    unsigned int len = str->Length;
    array<wchar_t, 1>^ src = str->ToCharArray();
    int dstIdx = 0;
    for (unsigned int i = 0; i < len; i++) {
        wchar_t ch = src[i];
        switch (ch) {
        case L'\x20': case L'\xA0': case L'\u1680': case L'\u2000': case L'\u2001':
        case L'\u2002': case L'\u2003': case L'\u2004': case L'\u2005': case L'\u2006':
        case L'\u2007': case L'\u2008': case L'\u2009': case L'\u200A': case L'\u202F':
        case L'\u205F': case L'\u3000': case L'\u2028': case L'\u2029': case L'\x09':
        case L'\x0A': case L'\x0B': case L'\x0C': case L'\x0D': case L'\x85':
            continue;
        default:
            src[dstIdx++] = ch;
            break;
        }
    }
    return gcnew String(src, 0, dstIdx);
}

找到了这个此处 ...


您不能使用-u0022,因为您不能使用
通用字符名称来指定基本
字符集中的字符。

"You cannot use - u0022 because you cannot use a universal character name that designates a character in the basic character set."

这篇关于为什么会出现错误C3851(通用字符名称不能在基本字符集中指定字符)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆