c++ - 是否有从 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 命令,在我的程序中一切正常。非常感谢任何指导。
解决方案
推荐阅读
- spring - 在 Spring Boot 应用程序中实现 HATEOAS 时出错:java.lang.IllegalArgumentException
- mongodb - 将数据从一个集合复制到另一个集合 - MongoDB
- sql - Entity Framework Core 重命名数据库而不丢失插入的数据
- qt - Poppler:如何提取可填写的表单文本?
- wordpress - 媒体上传失败
- firebase - 在flutter firestore中获取currentUser文档的每个子集合
- c# - 如何在 C# 中从 Instagram API Sharp 返回当前趋势标签
- bitbucket-server - 有没有办法阻止对某些文件类型的更改使成功的构建无效?
- spring - Spring Cloud Config - 为具有多个配置文件的多个应用程序提供服务
- microservices - 学习nestJS时了解微服务