1

I'm using Visual Studio 2015, and I accidentally wrote two characters in a char, and, for some reason, the code compiled and I got an output on the screen (not even a warning).

#include <string>
#include <iostream>

int main() {
    std::cout << 'a ';
    std::string temp;
    std::getline(std::cin, temp);
    return 0;
}

The output is consistently:

24864

What's the logic behind the output?

MathuSum Mut
  • 2,765
  • 3
  • 27
  • 59
  • That's because VC++ tries to implement the C++ Standard, and the C++ Standard describes what character literals are (which include the construction in your code). – Kerrek SB Jan 05 '17 at 15:14
  • 2
    [this question](http://stackoverflow.com/questions/3960954/c-multicharacter-literal) contains the answer. – NathanOliver Jan 05 '17 at 15:15
  • Aha. The vaunted 'implementation defined.' – nicomp Jan 05 '17 at 15:16

1 Answers1

1

Because those are so-called 'multi char' literals. On most current implementations, they can have up to 4 individual characters in them.

SergeyA
  • 61,605
  • 5
  • 78
  • 137