【发布时间】:2013-08-12 22:54:51
【问题描述】:
每个人。我知道有很多相关的线程,但我不能很好地理解它们,所以我决定自己写。
我正在尝试编写一个 Win32 控制台应用程序,这是我想做的:
假设我的名字app是:MyApp.exe,所以我想每次在命令行输入:
MyApp.exe -W Hello
我的应用在输出中写入“Hello”。与其他论点相同。基本上,我想控制我想要的每一个参数,但我不知道该怎么做。
这就是我所拥有的:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
int main(int argc, char *argv [])
{
int count;
printf("This program was called with \"%s\". \n", argv[1]);
printf("\n");
system("Pause");
}
我的意思是,我知道每个参数都在 argv 数组中,但我不知道如何解析它,例如:
if(argv[1] == "-W")
它不起作用。
非常感谢!
【问题讨论】:
-
假设你忘记了这个问题上的“C”语言标签,标签上这个,看看this possible duplicate