Visual C ++中的argc和argv [英] argc and argv in Visual C++
问题描述
使用以下测试程序,即使命令参数是Hello World,argc的值也始终为1。我做错了什么?
测试程序:
#include< stdio.h>
#include< ; stdlib.h>
#include< string.h>
char * out_filename;
FILE * output_file;
errno_t err;
int main(int argc,char * argv [])
{
out_filename = * ++ argv; //包含元素的文件名称
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; //语法和说明。
if((err = fopen_s(& output_file," out_filename"," w"))!= 0)返回0;
fprintf(output_file," Hello World \ nn \ n");
fprintf(output_file," Program name:%s \ n",argv [0]);
返回1;
if(strcmp(" Hello",argv [1])== 0)返回0;
fprintf(output_file,"%s",argv [1]);
fprintf(output_file,"%s",argv [2]);
fclose(output_file);
返回1;
}
告诉我们如何调用可执行文件并传递命令行参数。 />
With the following test program, the value of argc is always 1, even though the command arguments are Hello World. What am I doing wrong?
Test program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *out_filename;
FILE *output_file;
errno_t err;
int main(int argc, char* argv[])
{
out_filename = *++argv; // Name of file containing element
// syntax and descriptions.
if ((err = fopen_s(&output_file, "out_filename", "w")) != 0) return 0;
fprintf(output_file, "Hello World\n\n");
fprintf(output_file, "Program name: %s \n", argv[0]);
return 1;
if (strcmp("Hello", argv[1]) == 0) return 0;
fprintf(output_file, "%s", argv[1]) ;
fprintf(output_file, "%s", argv[2]) ;
fclose(output_file);
return 1;
}
Show us how you are invoking the executable and passing the command line parameters.
这篇关于Visual C ++中的argc和argv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!