C++ 命令行参数学习

2024-01-03 19:47:06
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char *argv[], char *envp[])
{
	bool numberLines = false;    // Default is no line numbers.

								 // If /n is passed to the .exe, display numbered listing
								 // of environment variables.
	if ((argc == 2) && _stricmp(argv[1], "/n") == 0)
		numberLines = true;

	// Walk through list of strings until a NULL is encountered.
	for (int i = 0; envp[i] != NULL; ++i)
	{
		if (numberLines)
			cout << i << ": "; // Prefix with numbers if /n specified
		cout << envp[i] << "\n";
	}

	for (int i = 0; i < argc; ++i)
	{
		std::cout << "命令行参数: " << i << ": " << argv[i] << std::endl;
	}
}

argc是参数的数量;argv是一个数组,argv[0]是程序名,argv[1]是第一个参数,......;这是标准C++的&#x

文章来源:https://blog.csdn.net/bcbobo21cn/article/details/135370045
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。