在代码中设置 char** argv [英] setting up char** argv in code

查看:22
本文介绍了在代码中设置 char** argv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个名为 prog.exe 的程序,它以

So I have a program called prog.exe that starts with

int main(int argc, char** argv)

我传递给它的参数是

prog.exe news-rec

或prog.exe news-rec -t -p

or prog.exe news-rec -t -p

我如何在代码中配置这些参数的值,以便我不必从命令行运行程序.

How could I configure the values of these parameters in code so that I dont have to run the program from command line.

例如

prog.exe news-rec

我认为 argc = 1 但我将如何配置 argv 它将是什么?我试着做

I think argc = 1 but how will I configure argv what will it be? I tried doing

argv[0] = "news-rec";

但这不起作用

推荐答案

因为 argv[0] 包含可执行文件本身的名称.试试

Because argv[0] contains the name of the executable itself. Try

argc = 2;
argv[1] = "news-recc";

这篇关于在代码中设置 char** argv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆