How to pass command line arguments to a c program(如何将命令行参数传递给 c 程序)
问题描述
自从我学会编程以来,我就知道如何编写一个接受命令行参数的程序.我不明白的是这些参数如何获得它们的值.希望我没有将这两者混为一谈,但是参数和参数之间是有区别的.argument 是函数被调用时赋予的值,例如: foo( a, b, c);其中 a、b 和 c 是值.参数是调用时函数内部的值.
I've known how to write a program that accepts command line arguments ever since I learned to program. What I don't understand is how these parameters get their values. Hopefully I don't have these two mixed up but there is a difference between an argument and a parameter. An argument is the value given to the function when it is called such as: foo( a, b, c); where a, b, and c are the values. A parameter is the values that are inside the function while is being called.
所以我的问题是一个人如何将命令行参数传递给程序?我了解如何读取参数,argc 是参数的数量,argv 是指向包含参数等的字符串数组的指针,等等,但我只是不知道如何给这些参数赋值..
So my question is how does a person pass command line arguments to a program? I understand how to read the arguments, that argc is the number of arguments, argv is a pointer to an array of strings containing the arguments, etc. etc. but I just don't know how to give those arguments a value..
我正在寻找有关 C 和 C++ 的信息.我是这方面的新手.
I'm looking for information for both C and C++. I'm sort of a novice at this.
推荐答案
在 Windows 环境中,您只需像这样在命令行上传递它们:
In a Windows environment you just pass them on the command line like so:
myProgram.exe arg1 arg2 arg3
argv[1] 包含 arg1 等
argv[1] contain arg1 etc
主要功能如下:
int main (int argc, char *argv[])
这篇关于如何将命令行参数传递给 c 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将命令行参数传递给 c 程序
基础教程推荐
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
