#include #include #include #include using std::string; using std::size_t; int main() { const char *nargv[3]; string arg1("echo"); nargv[0] = arg1.c_str(); string arg2("test"); nargv[1] = arg2.c_str(); nargv[2] = NULL; // Unfortunately the prototype of execvp does not like const char*, // actually not const char* nargv[] coming from .c_str(). So either // we copy everything into newly allocated variables or we force it // with a cast. const_cast() - Is this OK? if ( execvp(nargv[0], const_cast(nargv) ) < 0 ) { perror("Execvp error. Aborting."); exit(1); } return 1; }

AltStyle によって変換されたページ (->オリジナル) /