Remember: on Unix, everything is a file (well, granted, almost everything).
Your current shell code actually means: write the value 50 (echo 50
) into the file (redirection operator >
) which name follows (/sys/class/backlight/acpi_video0/brightness
).
In C++, just open /sys/class/backlight/acpi_video0/brightness
as a file and read/write to it using whatever method you prefer: C++ fstream
, C fopen/fread/fwrite
, ...
Example with fstream
(namely ofstream
since we're only writing to it):
std::ofstream file("/sys/class/backlight/acpi_video0/brightness");
if (!file.is_open())
throw std::runtime_error("Could not open the file");
file << 50;
file.close();