I'm having trouble getting system() to run a command in a string variable.
ostringstream convert;
convert << getSeconds(hours);
string seconds = convert.str(); /* converts the output of 'getSeconds()' into
a string and puts it into 'seconds' */
string cmd = "shutdown /s /t " + seconds;
system(cmd);
getSeconds() just takes an int in hours, converts it into seconds and returns an int in seconds. Everything runs fine, no errors, until it reaches system(cmd);. The compiler then spits out this error:
error: cannot convert 'std::string {aka std::basic_string<char>}' to
'const char*' for argument '1' to 'int system(const char*)'
Here are my includes:
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
system(cmd.c_str());