system() が文字列変数でコマンドを実行するのに問題があります。
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()
時間単位の int を取り、それを秒単位に変換して、秒単位の int を返すだけです。に達するまで、すべてが正常に実行され、エラーは発生しませんsystem(cmd);
。次に、コンパイラは次のエラーを吐き出します。
error: cannot convert 'std::string {aka std::basic_string<char>}' to
'const char*' for argument '1' to 'int system(const char*)'
これが私のインクルードです:
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>