I'm getting this error when I try to read the output of a command line by line:
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); }
note: template argument deduction/substitution failed: note:
‘std::string {aka std::basic_string}’ is not derived from ‘std::basic_istream<_CharT, _Traits>’ exec(command), line <- Error