正在尝试从std::cout执行.exe 我有一个C++程序,它读取配置文件并获取目录。 我现在要做的是使用配置文件中的目录设置执行一个.exe程序

正在尝试从std::cout执行.exe 我有一个C++程序,它读取配置文件并获取目录。 我现在要做的是使用配置文件中的目录设置执行一个.exe程序,c++,std,C++,Std,下面是我的一段代码: int main(){ ConfigFile cfg("htbaseconfig.properties"); bool exists = cfg.keyExists("backuplocation"); exists = cfg.keyExists("logdir"); exists = cfg.keyExists("execdir"); exists = cfg.keyExists("fulldir"); exists = cfg.keyExists("incdir"

下面是我的一段代码:

int main(){

ConfigFile cfg("htbaseconfig.properties");

bool exists = cfg.keyExists("backuplocation");
exists = cfg.keyExists("logdir");
exists = cfg.keyExists("execdir");
exists = cfg.keyExists("fulldir");
exists = cfg.keyExists("incdir");
exists = cfg.keyExists("appdir");

std::string bkploc = cfg.getValueOfKey<std::string>("backuplocation");
std::cout << "Backup Location: " << bkploc << "\n";

std::string bkplogdir = cfg.getValueOfKey<std::string>("logdir");
std::cout << "Log Location: " << bkplogdir << "\n";

std::string bkpexec = cfg.getValueOfKey<std::string>("execdir");
std::cout << "Exec Directory: " << bkpexec << "\n";

std::string bkpfulldir = cfg.getValueOfKey<std::string>("fulldir");
std::cout << "Full Directory: " << bkpfulldir << "\n";

std::string bkpappdir = cfg.getValueOfKey<std::string>("appdir");
std::cout << "Real app Directory: " << bkpappdir << "\n\n\n";

for( ; ; ) {

Sleep(6000);

ShellExecute(NULL, L"open", , L"C:\\teste.htm", NULL,SW_SHOWNORMAL);

}

std::cin.get();
return (0);}

我该怎么做?我想用我在
std::cout
上得到的变量执行我的程序,您必须向ShellExecute传递一个包含所有参数的字符串(c字符串,一个char[]),而不是第二个NULL,就像将它们传递到命令行一样

所以会是这样的

ShellExecute(NULL, L"open", , L"C:\\teste.htm", "option=param option2=param2",SW_SHOWNORMAL);

取决于您如何从另一个exe文件中解析它们(或如何解析它们)

std::string
s可以连接,尽管您会遇到麻烦,因为您确实需要使用
std::wstring
s。
ShellExecute(NULL, L"open", , L"C:\\teste.htm", "option=param option2=param2",SW_SHOWNORMAL);