相关疑难解决方法(0)

(和其他unicode字符)在g ++不允许的标识符中

我是 发现我不能用 作为g ++ 4.7的有效标识符,即使-fextended-identifiers启用了该选项:

int main(int argc, const char* argv[])
{
  const char*  = "I'm very happy";
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp:3:3:错误:stogram'\ 360'在程序
main.cpp中:3:3:错误:stray'\ 237'在程序
main.cpp中:3:3:错误:stray'\'230'in程序
main.cpp:3:3:错误:在程序中迷路'\ 203'

经过一些谷歌搜索后,我发现标识符中尚不支持UTF-8字符,通用字符名称应该有效.所以我将我的源码转换为:

int main(int argc, const char* argv[])
{
  const char* \U0001F603 = "I'm very happy";
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp:3:15:错误:通用字符\ U0001F603在标识符中无效

所以显然不是有效的标识符字符.但是,该标准特别允许来自10000-1FFFD附件E.1 范围内的字符,并且不允许它作为E.2中的初始字符.我的下一个努力是看看是否有任何其他允许的unicode字符工作 - 但我没有尝试过.甚至不是重要的PILE OF POO()角色.

那么,为了有意义和描述性的变量名称,给出了什么?请问-fextended-identifiers这样做,因为它会公布或不?它是否仅在最新版本中得到支持?其他编译器有什么样的支持?

c++ unicode gcc g++ c++11

56
推荐指数
3
解决办法
8384
查看次数

在Visual Studio或GCC中使用表情符号作为c ++中的标识符名称

传统上,接受的字符我们可以如在C++是一个标识符的一部分使用_, a-z, A-Z0-9第一个字符之后.

有没有办法配置Visual Studio或GCC接受表情符号作为标识符名称(或任何其他任意unicode字符)的一部分?

int a = 2,  = 3;
++;  *= 2;
int ?(int a, int b) {return a + b;}
cout << ?(a * , 3) << endl;

const double ? = 3.14159;
double ? = sin(? / 2.0);
Run Code Online (Sandbox Code Playgroud)

c++ compilation g++ visual-studio

14
推荐指数
1
解决办法
8758
查看次数

为什么这些 Unicode 变量名称不能与 -fextended- 标识符一起使用?“, “ 和 ?

我听说可以使用 Unicode 变量名-fextended-identifiersGCC 中的标志来使用 Unicode 变量名。所以我用C++编写了一个测试程序,但它无法编译。

\n
#include <iostream>\n#include <string>\n\n#define \xc2\xac !\n#define \xe2\x89\xa0 !=\n#define \xc2\xab <<\n#define \xc2\xbb >>\n\n/* uniq: remove duplicate lines from stdin */\nint main() {\n    std::string s;\n    std::string t = "";\n    while (cin \xc2\xbb s) {\n        if (s \xe2\x89\xa0 t)\n            cout \xc2\xab s;\n        t = s;\n    }\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我收到这些错误:

\n
#include <iostream>\n#include <string>\n\n#define \xc2\xac !\n#define \xe2\x89\xa0 !=\n#define \xc2\xab <<\n#define \xc2\xbb >>\n\n/* uniq: remove duplicate lines from stdin */\nint main() {\n    std::string s;\n    std::string t …
Run Code Online (Sandbox Code Playgroud)

c++ unicode gcc variable-names

5
推荐指数
2
解决办法
5581
查看次数

标签 统计

c++ ×3

g++ ×2

gcc ×2

unicode ×2

c++11 ×1

compilation ×1

variable-names ×1

visual-studio ×1