Arduino with C ++

What I try to do is run C / C ++ code on arduino for the computer eg use of C ++ libraries and run this C ++ code on the computer
An example create a file on the computer with C ++:

#include
#include

std::ofstream outfile (“test.txt”);

outfile << “my text here!” << std::endl;

outfile.close();

What I want is that when connecting the arduino can execute “Automatically” this code in the computer Is there any way to be able to perform this action?

No, the Arduino can’t execute code from the computer. You’ll have to compile the code for the Arduino and load it on the Arduino. Moreover, the Arduino doesn’t have a file system because it doesn’t have any storage media. For something like creating a file you’d have to add an SD card reader and use the SD library to write and read the file. So the code will look quite different when written for the Arduino.

I want create files in the "Computer" not in the Arduino

If you want something to happen on your PC when an Arduino is connected you will need to have a program running on the PC that continually checks whether the Arduino is connected.

An Arduino cannot cause a program to run on a PC.

Perhaps one exception to that is if a Leonardo or Micro is programmed to act as a keyboard in which case it could send keystrokes to the PC which might be capable of causing it to do what you want. Check out the keyboard capabilities

…R

Then what is the purpose of the code on the Arduino? If all the action is on the PC then just write code on the PC.

Robin2:
If you want something to happen on your PC when an Arduino is connected you will need to have a program running on the PC that continually checks whether the Arduino is connected.

An Arduino cannot cause a program to run on a PC.

Perhaps one exception to that is if a Leonardo or Micro is programmed to act as a keyboard in which case it could send keystrokes to the PC which might be capable of causing it to do what you want. Check out the keyboard capabilities

...R

Arduino execute code in the computer when connection with the usb, ¿why not is possible?

Are you wanting a USB Rubber Ducky?

How can Arduino code execute in a computer?

Arduino code is compiled for an Atmega microprocessor - not for the processor on your PC.

This is all just a waste of time. You need to explain what your project is all about.

...R

The library Keyboard and Mouse execute code in the computer...

No they do not. The code running on the Arduino communicates with the computer over the USB connection according to a defined protocol (USB-HID). The computer accepts and interprets these messages and performs the appropriate action according to the protocol spec.

Everything that happens with the Keyboard and Mouse library happens because the computer allows it to. If you program the computer to ignore the Arduino (like disabling the device in Device Manager), there is nothing the Arduino can do to make it listen.

You have been told what you need to do. If you want a PC program to run when the Arduino is plugged in, you need to write code on the PC in addition to the Arduino, because the PC is in control of itself.