argc&argv parameters in C++

argc: the number of parameters

argv: the list of paramters

#include <iostream>
using namespace std;

int main(int argc, char*argv[])
{
	cout << argc << endl;
	if (argc > 3 || argc < 2) {
		cout << "The usage of Project2.exe is 'Project2 x', where x is a positive number." << endl;
		return 1;
	}
	cout << argv[1] << endl;
	for (int i = 1; i < atoi(argv[1]); i++) {
		cout << i << ' ';
		if (i % 10 == 0) {
			cout << endl;
		}
	}
	return 0;
}

Open terminal, go into the folder thats contains excution file, and run the following command:

projectName 50

where projectName is your project name, and the excution file is projectName.exe in Windows Operation System.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

17 − 17 =

84 − = 83