c++stringvisual-c++trigraphs

Why MSVC compiler converts "??-" sequence to "~" in string literals?


I have a hard coded string in my code (which should be used as a file mask), but compiler always changes the "??-" sequence to "~", for example:

const wchar_t textW[] = L"test-??-??-??.txt";

The testW will be "test-~~??.txt" (without quotes).

The same happens for non-unicode strings as well:

const char textA[] = "test-????-??-??.txt";

textA will be "test-??~~??.txt" (without quotes).

My compiler is Microsoft Visual C++ 2008.

I have just tried this with Visual Studio 2013, the string in runtime is correct and intellisense displays the correct value on the tooltip when I'm tracing the app, but... But in the writing mode (when app isn't running) intellisense displays incorrect value with tildas on the tooltip.


Solution

  • That's a trigraph, a way to express characters that are not always available on keyboards.

    This behavior is controlled by the /Zc:trigraphs option, which is off by default. It appears it is enabled for your project, I would suggest you disable it.