Escape sequence for ? in c++

落爺英雄遲暮 提交于 2021-02-07 04:46:32

问题


I was looking at the escape sequences for characters in strings in c++ and I noticed there is an escape sequence for a question mark. Can someone tell me why this is? It just seems a little odd and I can't figure out what ? does in a string. Thanks.


回答1:


It's to keep a question mark from getting misinterpreted as part of a trigraph.

For example, in

"What??!"

The "??! would be interpreted as the | character. So, you have to escape the question marks as follows:

"What\?\?!"

Example complements of http://msdn.microsoft.com/en-us/library/bt0y4awe%28VS.80%29.aspx



来源:https://stackoverflow.com/questions/1586834/escape-sequence-for-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!