'??'正在转换为 '^'在 Visual C 中。为什么会出现这样的情况,出路又是什么?

发布于 2024-08-28 18:31:22 字数 206 浏览 10 评论 0原文

'??' 则会转换为“^”

如果我编译 mn VC++ 程序并运行它,

sprintf( ch, "??") 

打印出来

^

但是如果我在Turbo C/C++中运行相同的代码,就不存在这样的问题。为什么Windows上的VC++会出现这种情况?

'??' gets converted into '^' if I compile mn VC++ program and run it

e.g.

sprintf( ch, "??") 

prints out

^

But if I run the same code in Turbo C/C++, there is no such problem. Why is it happening on VC++ on Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁憨憨 2024-09-04 18:31:22

?? 本身并不是一个 三字母,尽管 ? ?' 对应于^

也许您在此处键入的内容与代码中的内容不同,并且您看不到字符串中的尾随单引号,因为它太接近结束引号。

所以在代码中你可能有:

sprintf( ch, "??'");

?? alone is not a trigraph, although ??' corresponds to ^.

Perhaps you typed it here different from what you have in code and you can't see the trailing single quote in your string because it's too close to the closing quote.

So in code you probably have:

sprintf( ch, "??'");
王权女流氓 2024-09-04 18:31:22

您确定这是双引号而不是单引号吗?如果是 ??',那么您刚刚遇到了一个三字母,它是一个“功能”,确实应该删除,但这并不是因为 IBM 不从 EBCDIC 迁移到 UTF-8。 (当 C++0x 仍然开放更改时,曾考虑删除三字母组,但删除三字母组的举动遭到 IBM 及其在 ISO C++ 委员会的代表的强烈阻止)。

Are you sure it was a double-quote and not a single-quote? If it was ??', then you've just encountered a trigraph, which is a "feature" that really should be removed, but isn't due to IBM not migrating to UTF-8 from EBCDIC. (Trigraphs were considered for removal when C++0x was still open for changes, but the move to get trigraphs removed were vehemently blocked by IBM and its representatives at the ISO C++ committee).

贪了杯 2024-09-04 18:31:22

?? 通常序列开始一个三字符组,但序列“??”不是一个三字母,所以它不应该被解释为这样 - 也许编译器中有一个错误 - 您使用的是哪个版本,确切的代码是什么(包括变量声明)?

这段代码打印“??”正如您所期望的,在 MSVC 6 到 VS 2010 的多个版本中:

char ch[20];
sprintf( ch, "??");
printf( "%s\n", ch);

但是将 snprintf() 行替换为:

sprintf( ch, "'??'");

并且输出变为“'^”(VS 2010 中除外) )。

快速测试表明 VS 2010 默认禁用三字符支持(它在第二次测试中打印出“'??'”)。在 VS 2010 中,您必须使用 /Zc:trigraphs 选项显式启用三字母支持。好的。

有关什么是三字母组的更多详细信息,请参阅:C++ 中三字母组序列的用途?

The ?? usually sequence starts a trigraph, but the sequence "??" isn't a trigraph so it shouldn't be interpreted as such - maybe there's a bug in the compiler - exactly which version are you using, and what's the exact code (including variable declarations)?

This code prints "??" in several versions of MSVC 6 through VS 2010 as you might expect:

char ch[20];
sprintf( ch, "??");
printf( "%s\n", ch);

But replace the snprintf()line with:

sprintf( ch, "'??'");

and the output becomes "'^" (except in VS 2010).

A quick test shows that VS 2010 disables trigraph support by default (it prints out "'??'" in the 2nd test). In VS 2010 you have to explicitly enable trigraph support using the /Zc:trigraphs option. Nice.

For more details on what trigraphs are, see: Purpose of Trigraph sequences in C++?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文