[英]'??' is getting converted into '^' in Visual C++. Why is it happening and what is the way out?
'??' “?” gets converted into '^' if I compile mn VC++ program and run it
如果我编译mn VC ++程序并运行它,则转换为'^'
eg 例如
sprintf( ch, "??")
prints out 打印出来
^
But if I run the same code in Turbo C/C++, there is no such problem. 但是如果我在Turbo C / C ++中运行相同的代码,就没有这样的问题。 Why is it happening on VC++ on Windows?
为什么在Windows上的VC ++上会发生这种情况?
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 .
如果它是??',那么你刚刚遇到了一个三元组 ,这是一个真正应该删除的“特性” ,但不是因为IBM没有从EBCDIC迁移到UTF-8 。 (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).
(当C ++ 0x仍然可以进行更改时,考虑删除Trigraphs,但IBM及其代表在ISO C ++委员会中强烈阻止了删除三字母的举动)。
??
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, "??'");
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:
在您可能期望的几个版本的MSVC 6到VS 2010中:
char ch[20];
sprintf( ch, "??");
printf( "%s\n", ch);
But replace the snprintf()
line with: 但是用以下内容替换
snprintf()
行:
sprintf( ch, "'??'");
and the output becomes " '^
" (except in VS 2010). 输出变为“
'^
”(VS 2010除外)。
A quick test shows that VS 2010 disables trigraph support by default (it prints out " '??'
" in the 2nd test). 快速测试显示VS 2010默认禁用了三字母支持(在第二次测试中打印出“
'??'
”)。 In VS 2010 you have to explicitly enable trigraph support using the /Zc:trigraphs
option. 在VS 2010中,您必须使用
/Zc:trigraphs
选项明确启用trigraph支持。 Nice. 尼斯。
For more details on what trigraphs are, see: Purpose of Trigraph sequences in C++? 有关三字母是什么的更多详细信息,请参阅: C ++中Trigraph序列的用途?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.