我想在代码而不是main函数中声明和赋值给argc和argv,那么怎么做呢?我正在使用Qt。
答案 0 :(得分:2)
// Works but wherever you use argv you should use * with it.
int argc = 2;
char* arg1[1] = {"gstreamer"}; // Program Name
char* arg2[1] = {"/home/1.ogg"};
char** argv[2] = { arg1 , arg2};
另一种方法:
// Works without any need for *
char arg0[] = "gstreamer"; // Program Name
char arg1[] = "/home/1.ogg";
char* argv[] = { &arg0[0], &arg1[0], NULL };
int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1;
参考文献: