How to use C++ code in Arduino ide

Well the answers on how to read the picture buffer are in that thread.

But there are already examples of sending images to SD card on the ESP32CAM, for example do a Google search on;

'espcam32 save image to sd'

yes, I'm asking if I need to sum the values in fb->buf[i] as any array but I need this code of summation in separate file , sent the value of array buf[i] to the summation code ,
how to generate this function in file and I include it in arduino ide? for example this
function in separate file
int sum(int buf, int len)
int sum = 0;
for (int i = 0; i < len; i++)
sum += buf[i];
return sum;
now I need to include this function in arduino :
output = sum( buf, len)
I take summation function just for simplicity.

I know, but my main question is how to make function (I said function just to understand me, in fact I have algorithm) in separate file (.cpp) and in every time send array to this file . in arduino just calling the name of function

extern int sum (int*, int);

Examples here;

seems this is related to our previous conversation and code I gave you here

why did you create a new thread?

also it seems you had working code doing

fb = esp_camera_fb_get();
for (int i = 0; i < fb->len; i++){

so it was just a matter of replacing it in your existing code...

At the right end of the little bar just above your sketch there is a triangle in a box. Click on that and select New Tab from the menu that drops down. Name that tab "something.cpp". Put your C++ code in that new tab.

In your sketch put the line suggested above to let your sketch know that the function in the .cpp file exists:
extern type name(arglist);

Now your sketch can call that C++ function.

To get fancier, make another new tab and name it 'something.h'. Put the 'extern' lines in there and add
#include "something.h"
to the top of your sketch.

If you want to use that C++ code in more than one sketch you can move the .h and .cpp to:
sketch folder/libraries/something/something.cpp
sketch folder/libraries/something/something.h

I see. You very cleverly copied the code that someone else copied from one of the ESP32-CAM examples.

thanks a lot, I did that, I have another question please, can I deal with file (.txt) ? my function read the input from file, the function in (.cpp file) be like this
void dosomething()
ifstream fin("brb.txt"); //file to be read
ofstream fcom("c9999999omjp.txt"); // the output of function putting in this file

// rest of the function
and the output of this fb = esp_camera_fb_get(); after printing be like this :
how can I sent this output to the function dosomething() ? can you help please?

Whatever system that C++ code was written for has an operating system and file system. The Arudino has neither. You can open, read, and write files on an SD Card if you add an SD Card module and use the SD library. See:

Why don’t you pass the fb Variable by reference to your function and let your function extract the image content.

As mentioned already once, this seems very related to your other post… should those be merged ?

Also if you were to take a step back and tell us exactly what you want to achieve, we might provide a better solution than what you can think of… feeling an XY problem here…

As well as also sensing an XY problem, the questions being asked are at the fairly basic level, whereas subsequent actual 'processing' of some unknown type of this image data is likely to be of a fairy advanced level ...........

Can you see the question update please? I need to send fb->buf[i] to the function to handle its contents . Can u help please?

I made it a different title to make it easier for those who come after me to search and find a solution.
Can you see the question update please? I need to send fb->buf[i] to the function to handle its contents . Can u help please?

This compiled for me for an ESP32 processor:

main sketch (.ino)

extern void dosome();

void setup()

void loop() {}


#include <iostream>
using namespace std;
#include <fstream>
#include <string>

#include <Arduino.h>

void dosome()
  char key, ch;
  string str;
  int freq = 1;
  ifstream fin("read.txt");     //file to be compressed
  ofstream fcom("write.txt");
  // file into which the compressed data will be stored
  fin >> key;
  while (getline(fin, str))
    // to read the data line-by-line till all lines are read
    for (int i = 0; i <= str.length(); i++)
      // read one character at time from the string
      if (i == str.length())
        // if all characters from the string have been read
        fcom << key << freq << endl;
        key = fin.peek();
        freq = 0;
      else if (key == str[i])
        fcom << key << freq;
        key = str[i];
        freq = 1;

Just pass the whole struct as reference

sorry, you just call the function, how can I write "buf[i]" in this " read.txt"

How can I do?

Are you going to explain why you want to do this ?

I'm just need to now how can I deal with this problem" how can send "buf[i]" to the function to be written in the file "read.txt"
For four days I have been searching for a solution to this problem with no avail :frowning: