Error when i execute my program . (C++) : I had some problems with my c++ program on my raspberry when i execute the program. The Program consist to take data from the arduino from the captor.
Thus I think that the problem cannot come from the arduino because the program of the arduino worked with a program python but for certain reasons I need to use C ++ I shall like to know how to solve my problem I am a little bit pressed for time because it is a university project.
so this is my program :

    #include "SerialPort.h" //My library

    SerialPort::SerialPort() //Constructor
    {
	    this->numCon = open("/dev/ttyACM0", O_RDWR| O_NOCTTY ); //ttyACM0 arduino port
	
        this->connected = false;

	    struct termios tty;
	    struct termios tty_old;
	    memset (&tty, 0, sizeof tty);

	    /* Error Handling */
	    if ( tcgetattr ( this->numCon, &tty ) != 0 ) {
		    std::cout << "Error " << errno << " from tcgetattr: " << strerror(errno) << std::endl;
		    return;
	    }

	    /* Save old tty parameters */
	    tty_old = tty;

	    /* Set Baud Rate */
	    cfsetospeed (&tty, (speed_t)B9600);
	    cfsetispeed (&tty, (speed_t)B9600);

	    /* Setting other Port Stuff */
	    tty.c_cflag     &=  ~PARENB;            // Make 8n1
	    tty.c_cflag     &=  ~CSTOPB;
	    tty.c_cflag     &=  ~CSIZE;
	    tty.c_cflag     |=  CS8;

	    tty.c_cflag     &=  ~CRTSCTS;           // no flow control
	    tty.c_cc[VMIN]   =  1;                  // read doesn't block
	    tty.c_cc[VTIME]  =  5;                  // 0.5 seconds read timeout
	    tty.c_cflag     |=  CREAD | CLOCAL;     // turn on READ & ignore ctrl lines

	    /* Make raw */
	    cfmakeraw(&tty);

	    /* Flush Port, then applies attributes */
	    tcflush(this->numCon, TCIFLUSH );
	    if ( tcsetattr (this->numCon, TCSANOW, &tty ) != 0) {
		    std::cout << "Error " << errno << " from tcsetattr" << std::endl;
		    return;
	    }
	
	    this->connected = true;
    }

    SerialPort::~SerialPort() //Destructor

> the program consist to take and send data on Serial port(Arduino) with a constructor.

    {
        if (this->connected) {
            this->connected = false;
        }
    }  

    char* SerialPort::readSerialPort()
    {
	    int n = 0, spot = 0;
	    char buf = '\0';

	    /* Whole response*/
	    char response[1024];
	    memset(response, '\0', sizeof response);

	    do {
		    n = read(this->numCon, &buf, 1 );
		    sprintf( &response[spot], "%c", buf );
		    spot += n;
	    } while( buf != '\r' && n > 0);

	    if (n < 0) {
		    std::cout << "Error reading: " << strerror(errno) << std::endl;
	    }
	    else if (n == 0) {
		    std::cout << "Read nothing!" << std::endl;
	    }
	    else {
		    std::cout << "Response: " << response << std::endl;
	    }
	
	    return response;
    }

    void SerialPort::writeSerialPort(unsigned char cmd[])
    {
	    int n_written = 0, spot = 0;
	    do {
		    n_written = write(this->numCon, &cmd[spot], 1 );
		    spot += n_written;
	    } while (cmd[spot-1] != '\r' && n_written > 0);
    }  

    bool SerialPort::isConnected()
    {
        return this->connected;
    }

And this is the library(SerialPort.h) :

    #ifndef SERIALPORT_H
    #define SERIALPORT_H

    #include <stdio.h>      // standard input / output functions
    #include <stdlib.h>
    #include <string.h>     // string function definitions
    #include <unistd.h>     // UNIX standard function definitions
    #include <fcntl.h>      // File control definitions
    #include <errno.h>      // Error number definitions
    #include <termios.h>    // POSIX terminal control definitions
    #include <iostream>
    class SerialPort
    {
	    private:
		   int numCon;
		   bool connected;
		
	    public:
		    SerialPort();
		    ~SerialPort();

		    char* readSerialPort();
		    void writeSerialPort(unsigned char cmd[]);
		    bool isConnected();
    };

    #endif // SERIALPORT_H

thanks for taking time to read my post.