Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why would std::string s("??<") output a { instead of ??< as expected?

std::string s("??<");
std::cout << s << std::endl;

Why does that output { instead of ??<

I'm using Visual Studio 2008. I'm assume it's encoding it but why and what is the encoding called if that is what's happening?

This little %#$^*! caused me to look for a bug in my (unit test) code for 30 minutes before I figured out my string was mangled!! :(

like image 246
cchampion Avatar asked Dec 16 '09 16:12

cchampion


1 Answers

Because of trigraphs.

These are the supported trigraphs, from the Wikipedia page:

  • ??=#
  • ??/\
  • ??'^
  • ??([
  • ??)]
  • ??!|
  • ??<{
  • ??>}
  • ??-~

For Visual Studio, according to the documentation trigraphs are turned off by default (sensibly enough), so check your project/makefiles.

like image 174
unwind Avatar answered Oct 20 '22 20:10

unwind