使用libcurl c ++将响应数据存储在post上的变量中

By running the file.cpp, curl_easy_perform(curl) prints the response from file.php as "[{"Aid_response":"1","Acd_response":"2"}]" in terminal.But how can I store it in a variable ? Please help me.

My file.cpp

  #include <iostream>
  #include <stdlib.h>
  #include <stdio.h>
  #include <curl/curl.h>

  using namespace std;
  size_t size = 0;

  int main () { 
  CURL *curl;
  CURLcode res;
  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  if(curl) 
  {
    curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/file.php");
    string out = "Aid=1&Acd=2";
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, out.c_str());
    res = curl_easy_perform(curl);
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s
",curl_easy_strerror(res));
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  return 0;
  }

My file.php

<?php
$Aid = $_REQUEST['Aid'];
$Acd = $_REQUEST['Acd'];
$data = array();
$data[] = array('Aid_response'=> $Aid, 'Acd_response'=> $Acd);
echo json_encode($data);
?>

I used CURLOPT_WRITEFUNCTION to store response to a variable and its working fine now.

Here is the file.cpp

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <curl/curl.h>

using namespace std;
size_t size = 0;

size_t write_to_string(void *ptr, size_t size, size_t count, void *stream) {
  ((string*)stream)->append((char*)ptr, 0, size*count);
  return size*count;
}
  int main () {
  CURL *curl;
  CURLcode res;
  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  if(curl) 
  {
    string out = string("http://localhost/canvas1/flix2.php?Aid=1&Acd=2");
    curl_easy_setopt(curl, CURLOPT_URL, out.c_str());
    string response;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
    res = curl_easy_perform(curl);
    cout << "Variable response : " << response;
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s
",curl_easy_strerror(res));
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
return 0;
}