vendredi 12 mars 2021

How to put variable as argument in system()

I am trying to include the sleep 1 command in bash in my .cpp file
While system("sleep 1") works fine, I would like to change 1 into a const int or string

const string t = "1";
string c = "sleep " + t;
system(c);

However, it seems like the system(c) is treated as a call to function as the following error occurs:

error: no matching function for call to 'system'
  system(c);

How can I resolve this?

Aucun commentaire:

Enregistrer un commentaire