It seems the << 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:
#include <string>
#include <iostream>
using namespace std;
int main() {
string string1 = "C";
string string2 = "D";
cout << "A" "B"; //This compiles and outputs "AB"
cout << string1 string2; //This doesn't compile
return 0;
}
As noted in the comments the line cout << "A" "B";
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.
Why does the compiler treat these two lines differently? If it's concatenating string literals, shouldn't it also concatenate string variables?
What is happening implicitly and why doesn't it happen to both string literals and variables?
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.