【发布时间】:2014-12-10 21:20:49
【问题描述】:
当我尝试逐行读取命令行的输出时出现此错误:
std::string exec(const char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe) return "";
char buffer[128];
std::string result = "";
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != NULL) {
result += buffer;
}
}
pclose(pipe);
return result;
}
string commandStr = "echo Hello World";
const char *command = commandStr.c_str();
std::string output = exec(command);
std::string line;
while (std::getline(output, line)) {
send(sockfd, line.c_str(), line.length(), 0);
}
注意:模板参数扣除/替换失败:注意:
'std::string {aka std::basic_string}' 不是从 'std::basic_istream<_chart _traits>' 执行(命令),行
【问题讨论】:
标签: c++