std::string s("??<");
std::cout << s << std::endl;
为什么输出 { 而不是 ??<
我使用的是 Visual Studio 2008。我假设它正在对其进行编码,但如果发生这种情况,为什么以及调用的编码是什么?
这个小 %#$^*!让我在我的(单元测试)代码中寻找错误 30 分钟,然后我才发现我的字符串被破坏了!! :(
最佳答案
因为trigraphs .
这些是支持的三字母组,来自维基百科页面:
-
??=
→#
-
??/
→\
-
??'
→^
-
??(
→[
-
??)
→]
-
??!
→|
-
??<
→{
-
??>
→}
-
??-
→~
对于 Visual Studio,根据 the documentation三字母组默认关闭(足够明智),因此请检查您的项目/makefile。
关于c++ - 为什么 std::string s ("??<") 输出 { 而不是预期的 ??< ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1916039/