title: Why can 2 string literals be concatenated but not two string variables?
body: <p>It seems the &lt;&lt; operator is able to stream two string literals to cout side by side whereas it's not able to stream two string variables side by side because two string literals are implicitly concatenated whereas two string variables are not. Here's a code example to showcase this:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      string string1 = "C";
      string string2 = "D";
  
      cout &lt;&lt; "A" "B"; //This compiles and outputs "AB"
      cout &lt;&lt; string1 string2; //This doesn't compile
  
      return 0;
  }
  </code></pre>
  
  <p>As noted in the comments the line <code>cout &lt;&lt; "A" "B";</code> compiles and outputs "AB". There seems to be some sort of implicit concatenation of these two string literals. But the next line doesn't not compile. That seems to indicate that a lack of that same implicit concatenation for some reason.</p>
  
  <p><strong>Why does the compiler treat these two lines differently? If it's concatenating string literals, shouldn't it also concatenate string variables?</strong> </p>
  
  <p><strong>What is happening implicitly and why doesn't it happen to both string literals and variables?</strong></p>
  
  <p>EDIT: It does seem close to the linked possible duplicate question but that question asks "Why is this behavior (implicit concatenation of string literals) in the language?" whereas mine asks, "Why is this done with string literals but not string variables.</p>