title: Why won't these strings concatenate in C++?
body: <p>I have an example of two test programs I wrote in C++. The first one works fine, the first one errors. Please help me to explain what is going on here.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdint.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  string randomStrGen(int length) {
  static string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  string result;
  result.resize(length);
  for (int32_t i = 0; i &lt; length; i++)
      result[i] = charset[rand() % charset.length()];
  return result;
  }
  
  int main()
  {
  ofstream pConf;
  pConf.open("test.txt");
  pConf &lt;&lt; "rpcuser=user\nrpcpassword=" 
       + randomStrGen(15)
       + "\nrpcport=14632"
       + "\nrpcallowip=127.0.0.1"
       + "\nport=14631"
       + "\ndaemon=1"
       + "\nserver=1"
       + "\naddnode=107.170.59.196";
  pConf.close();
  return 0;
  }
  </code></pre>
  
  <p>It opens 'test.txt' and writes the data, no problem. This, however, does not:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdint.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  string randomStrGen(int length) {
  static string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  string result;
  result.resize(length);
  for (int32_t i = 0; i &lt; length; i++)
      result[i] = charset[rand() % charset.length()];
  return result;
  }
  
  int main()
  {
  ofstream pConf;
  pConf.open("test.txt");
  pConf &lt;&lt; "rpcuser=user\n"
       + "rpcpassword=" 
       + randomStrGen(15)
       + "\nrpcport=14632"
       + "\nrpcallowip=127.0.0.1"
       + "\nport=14631"
       + "\ndaemon=1"
       + "\nserver=1"
       + "\naddnode=107.170.59.196";
  pConf.close();
  return 0;
  }
  </code></pre>
  
  <p>The only difference in the second program is that 'rpcpassword' has been moved to the next line.</p>
  
  <pre><code>matthew@matthew-Satellite-P845:~/Desktop$ g++ test.cpp 
  test.cpp: In function ‘int main()’:
  test.cpp:23:6: error: invalid operands of types ‘const char [14]’ and ‘const char [13]’ to binary ‘operator+’ 
    + "rpcpassword="
  </code></pre>