There are several C++ libraries to do this. But each one has its own peculiarities, however, we will mention the majority at the end of this article.
In this example we will see how to use Clip.
Clip is a cross-platform C++ library (Windows, macOS and GNU/Linux) for copying/pasting content from the clipboard.
The simplest way to use is:
string
:
main.cpp
CMakeLists.txt
Change the CMake version to your version, I put this version for compatibility reasons, but there will probably be a warning when running it, but it will work!
When running the binary, try typing: Ctrl + v
somewhere else and notice that the content was copied!
NOTE: This may not work in window managers, you need to configure files for compatibility, despite the xclip command work normally!
But, I tested it on GNOME and Windows and it worked perfectly!
For more information, visit the Clip repository.
And as I said, there are many options for it, including: