title: How to post data including a line break with libcurl (for Influxdb)?
body: <p>I am posting datapoints to InfluxDB using <code>libcurl</code> in C++. Single data points are working, but for multiple points, I am struggling on the necessary linebreak (\n), as defined in the <a href="https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint" rel="nofollow noreferrer">InfluxDB HTTP API</a>:</p>
  <blockquote>
  <p>Write several points to the database with one request by separating each point by a new line.</p>
  <p>Write points from a file with the @ flag. The file should contain a batch of points in the Line Protocol format. Individual points must be on their own line and separated by newline characters (\n). Files containing carriage returns will cause parser errors.</p>
  </blockquote>
  <p>I guess it might be an issue with the char formatting, but I can't figure out why? The following code just writes the 5 in distance but should write both distances.</p>
  <pre><code>#include &quot;stdafx.h&quot;
  #include &quot;tchar.h&quot;
  #include &lt;string&gt;
  #include &lt;curl\curl.h&gt;
  #include &lt;sstream&gt;
  
  int main()
  {
      int dataPoints[] = { 3, 5 };
      std::string fieldIdentifier = &quot;distance&quot;;
  
      std::stringstream ss;
  
      for (int i = 0; i &lt; 1; i++) {
          ss &lt;&lt; &quot;aufbau1,ort=halle &quot;;
          ss &lt;&lt; fieldIdentifier;
          ss &lt;&lt; &quot;=&quot; &lt;&lt; dataPoints[i];
          ss &lt;&lt; std::endl; //I guess this is the problem, it adds \n
      }
  
      ss &lt;&lt; &quot;aufbau1,ort=halle &quot;;
      ss &lt;&lt; fieldIdentifier;
      ss &lt;&lt; &quot;=&quot; &lt;&lt; dataPoints[1];
  
      std::string data = ss.str();
      const char *dataChar = data.c_str();
      
      CURL *curl;
      CURLcode res;
      curl_global_init(CURL_GLOBAL_ALL);
      curl = curl_easy_init();
  
      if (curl) {
          curl_easy_setopt(curl, CURLOPT_URL, &quot;http://myIP:8086/write?db=testdb&amp;u=myUser&amp;p=myPwd&quot;);
          curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dataChar);
          res = curl_easy_perform(curl);
  
          /* Check for errors */
          if (res != CURLE_OK)
              fprintf(stderr, &quot;curl_easy_perform() failed: %s\n&quot;,
                  curl_easy_strerror(res));
  
          curl_easy_cleanup(curl);
      }
      return 0;
  }
  </code></pre>