Page History
...
Code Block |
---|
// *.h : class A { public: static const int INT_PAR = 185; static const double DOUBLE_PAR; } // *.cpp : const int A::INT_PAR; const double A::DOUBLE_PAR = 109.92; |
Issue OS command from C++
Use method system
Code Block |
---|
// int system (const char* command);
#include <stdlib.h> /* system, NULL, EXIT_FAILURE */
int status = system ("ls -l"); |
Use method popen
Code Block |
---|
#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;
} |
Overview
Content Tools