简体   繁体   English

MSVS命令行参数

[英]MSVS command line arguments

Yo.txt

#include "hmap.h"

int main(char* argv[], int argc)
{
    printf("%s", argv[0]); <---- fails here
    system("pause");
    fileOpen(argv[1]);

    return 0;
}

I am using MSVS 2012. I'm wondering if I'm using the command line arguments wrong. 我正在使用MSVS2012。我想知道我是否使用了错误的命令行参数。 The text file is in the same folder. 文本文件在同一文件夹中。 All my header file has is the #include libraries I will using, some #define's I'll be using, and extern function prototypes. 我所有的头文件都是我将要使用的#include库,我将要使用的#define和extern函数原型。

When I run the program it says "expand.exe has stopped working...." 当我运行程序时,它说“ expand.exe已停止工作。

I usually program in a Linux environment using GCC but I'm trying to learn MSVS environment. 我通常在使用GCC的Linux环境中进行编程,但是我试图学习MSVS环境。 Getting a little frustrated on how much of a hassle to input command line arguments :. 对输入命令行参数的麻烦有一点沮丧。

I think the arguments for main() are around the wrong way. 我认为main()的论点是错误的。

That is, the first argument should be the argument count ( argv ), and the second one the argument vector ( argv ). 也就是说,第一个参数应为参数计数( argv ),第二个参数应为参数向量( argv )。

int main(int argc, char* argv[]) {}

It fails because a subscript should be used only with an array or pointer. 之所以失败,是因为下标只能与数组或指针一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM