是否有从StringStream读取输入的正确方法

时间:2020-09-17 02:14:41

标签: c++ c++11 vector stringstream

我正在编写一个自定义bash,它以串行和并行方式执行命令。当我尝试向终端回显任何内容时,在行的末尾会有一个空格,这使我无法通过测试用例。我的过程命令方法中有错误:

Commands commandProcess(std::string line, bool parallel, bool single) {
   // Create a list of commands to be returned if there
   // is processing occurring.
   Commands list; // vector of strings
   // Set up a string stream to read the line
   std::stringstream ss(line);
   std::string cl = ""; // clean line
   // While the string stream is still has unread info read
   // through quotes and assign the commands to a list.
   std::string temp = "";
   while (ss >> std::quoted(temp)) {
       cl += temp + " ";
       list.push_back(temp);
   }
   boost::trim_right(cl);
   std::cout << "Running: " << cl << std::endl;
   // Run a one line argument
   if (!parallel && single) {
       ChildProcess cp;
       cp.forkNexec(list);
       std::cout << "Exit code: " << cp.wait() << std::endl;
   }
   return list;
}

除echo命令外,所有程序在我的程序中均正常运行。任何指导都非常感激。

expectedoutput

0 个答案:

没有答案