简体   繁体   English

“?” 在Visual C ++中被转换为'^'。 为什么会这样,出路是什么?

[英]'??' 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.

相关问题 C ++。 什么是子程序和方法? - C++. What is a subprogram and method? C ++中的继承。 为什么错了? - Inheritance in c++. Why is it wrong? 无法在 C++ 中读取 txt 文件。 我不断收到我的 inputFile.fail 文本。 谁能帮我找出要解决的问题? - Unable to read txt file in c++. I keep getting my inputFile.fail text. Could anyone help me into figuring out what to fix? Visual C ++:无效的分配大小。 为什么会这样呢? - Visual C++: Invalid allocation size. Why is this happening? 尝试添加到C ++中的LinkedList。 获取SegFault - Trying to add to a LinkedList in C++. Getting a SegFault C++。 在模板化的 class 中初始化多个 static 变量的最佳方法是什么? - C++. What's the best way to initialize multiple static variables in a templated class? C ++。 为什么我不能编译此代码? 使用const_cast删除constness有什么问题? - C++. Why I can't compile this code? What is wrong with removing constness using const_cast? 为什么在C ++中会发生这种情况? - Why is this happening in C++? 与Visual C ++中的reverse_iterator相关的崩溃。 这是合法代码吗? - reverse_iterator related crashes in Visual C++. Is it legal code? Visual Studio 2008 C ++。 问题引用DLL项目 - Visual Studio 2008 C++. Problem Referencing DLL Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM