Assuming that you are communicating with gnuplot trougth a FIFO, you can order to gnuplot
print <variable>
and you can read this to your c++ program.
Eg. for reading a varirable:
double getVal(std::string val){
  
  float ret;
  std::string str;
  
  str="print "; str+=val;str+="\n";
  
  fprintf(gp, str.c_str());
  fflush(gp);
  
  fscanf(gpin, "%f", &ret);
  
  return ret;
}
To open a gnuplot FIFO
void connecttognuplot(){
  
    //make an unique FIFO
    std::stringstream alma; alma.str(std::string()); alma<<std::clock(); GPFIFO="./gpio"+alma.str();
  
    //gnuplot => program FIFO
    if (mkfifo(GPFIFO.c_str(), 0600)) {
    if (errno != EEXIST) {
        perror(GPFIFO.c_str());
        unlink(GPFIFO.c_str());
    }
    }
    // For fprintf
    if (NULL == (gp = popen("gnuplot 2> /tmp/gp1","w"))) {
    perror("gnuplot");
    pclose(gp);
    }
    //  Redirect print
    fprintf(gp, "set print \"%s\";\n", GPFIFO.c_str());
    fflush(gp);
    // For fscanf
    if (NULL == (gpin = fopen(GPFIFO.c_str(),"r"))) {
    perror(GPFIFO.c_str());
    pclose(gp);
    }
  
  }