我正在开发一个简单的程序,其中包含计算机名称的文件由 C++ 文件读取,如下所示:
//Previously, the file containing names was opened and
//getline() is in use to read each line
//note that 'line' is a string containing the current line being read
string comp = lower(trim(line.erase(0, 2)));
//lower converts to lowercase (for later in the program) and
//trim trims the beginning and ends of the string.
//I have erased the first two characters, since they contain two \'s
ofstream bat;
bat.open("names_get.bat");
if (bat.is_open()) {
bat << "wmic.exe /node:"+comp+" ComputerSystem Get UserName >CompNames.txt";
bat.close();
}
这一切都运行得很好。但是,当使用 shellexecute 执行此批处理文件时,我遇到了问题。我的问题是命令提示符遇到计算机名称,例如“Owner-PC”并将 - 作为参数,导致无效的全局切换错误。有人可以指出我在这种情况下如何逃脱冲刺的正确方向。谢谢你,很抱歉这个问题很长!