I found this example online from this forum and it has an example of how to read data from the system() call. I was wondering if this can read the data into a c++ string. And if so i dont understand how this example works. could some explain this code stub below. I know its just a pointer to a function but im not sure how data is captured in the calling application. As i see it, all it stores is the return value of the system() call and not the actual data from std out, im i wrong? Here is the example below.
#include <iostream>
using namespace std;
int (*ptr) (const char[]);
int main()
{
ptr = system;
....... procedure ......
....... work .......
ptr("clear");
return 0;
}
system is a function to pass commands to the shell. You can make a pointer to the function and call it just as a function with the command as the argument. So you have captured the command using an identifier.
It doesn't do anything. ptr is a variable that is assinged the address of the function system. Calling ptr("clear") is equivalent to calling system("clear").