I was trying to compile the code below (from https://stackoverflow.com/a/21829/ ... ) The compilation went fine if I compile
$ g++ test.cpp
but mistakenly when the -std=c++11 switch is used:
$ g++ -std=c++11 test.cpp test.cpp: In function 'std::string exec(char*)': test.cpp:6:32: error: 'popen' was not declared in this scope FILE* pipe = popen(cmd, "r"); ^
Any idea what is going on?
(I am using mingw32 gcc4.8.1 from mingw.org and on WindowsXP64)
Code:
#include <string> #include <iostream> #include <stdio.h> std::string exec(char* cmd) { FILE* pipe = popen(cmd, "r"); if (!pipe) return "ERROR"; char buffer[128]; std::string result = ""; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) result += buffer; } pclose(pipe); return result; } int main() {}
source share