4

Possible Duplicate:
What do single quotes do in C++ when used on multiple characters?

I was writing some C++ code over the weekend and by chance realised that the compiler has no qualms with single-quote strings - as long as they are 4 or less characters long.

(*by chance - When you use single-quote strings in javascript and SQL, you might find yourself getting them mixed up in other programming environments/languages)

Well, the outcomes are actually different. Look at the following lines:

cout << "Test" << endl;
cout << 'Test' << endl;
//! cout << 'Tests' << endl; // Lexical error: max of 4 characters in string exceeded

They compile without a hitch and you get the following results:

Test
1415923836

The third commented line wont compile citing a Lexical error. Can someone please explain to me what is happening here, or how C++ interprets the single-quote string?

Community
  • 1
  • 1
John Gathogo
  • 4,495
  • 3
  • 32
  • 48
  • Thanks guys. The link clarified things quite a lot. It just beats me that a search for "single quote string c++" on stackoverflow wont even list http://stackoverflow.com/questions/7459939/what-do-single-quotes-do-in-c-when-used-on-multiple-characters on the first 3 pages. Thanks all the same. – John Gathogo Nov 21 '11 at 06:26

0 Answers0