执行C ++程序的命令行参数 [英] command line arguments to execute a C++ program

查看:125
本文介绍了执行C ++程序的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的c ++程序的主要内容:

this is the main of my c++ program:

void main(int argc, char** argv, Arguments& arguments)

第一个参数是一个文件,其余参数是布尔值。

我想知道用于编译程序的命令行的正确语法是什么。

我尝试过:

the first arguments is a file and the rest are boolean values.
I was wondering what is the correct syntax for the command line to compile the program.
I tried:

gcc  -o "argument1" "argument2" "argument3" prog.cpp  

g++ -std=c++11 -o "argument1" "argument2" "argument3" prog.cpp

,但出现此错误:

linker command failed with exit code 1 (use -v to see invocation)

我怀疑我没有正确传递参数,因此我的程序无法正确链接到输入文件(argument1)。

感谢您纠正我。

I am doubting that I am not passing the arguments correctly and therefore my program doesn't link to the input file (argument1) correctly.
thank you for correcting me.

推荐答案

主要功能定义如下:

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

int main (int argc, char **argv)

据我了解,argc =参数计数,argv =参数向量。 argc是参数的数量(可以选择数量),而argv包含该参数的数量,其中包含要从命令行传递到程序中的所有实际数据。但是请记住,始终至少有一个参数要首先出现:程序的名称。

As I understand it, argc = Argument Count and argv = Argument Vector. argc is the number of arguments (you can choose how many), and argv contains that number of arguments, which contain all the actual data you want to pass in to your program from the command line. But remember there is always at least one argument which comes first: The name of the program.

这些在编译期间而不是在运行时使用。运行程序不同于编译和链接,后者必须首先完成(在您的情况下使用gcc)。

These are not used during compilation but during run time. Running the program is different from compiling and linking, which have to be done first (using gcc, in your case).

这篇关于执行C ++程序的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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