c++ 控制台输入参数

#include <iostream>
#include <string>

using namespace std;

int main(int argc,char **argv)
{
/*程序在启动是会通过main的参数传入参数,argc表示参数的个数(包括程序名),argv是一个字符串数组
它包含程序名称和每个参数;假如程序的运行命令如下: test.exe tt 22 33,则argc为4,argv为test.exe tt 22 33
*/
try
{
if(argc<4)
throw string("传入的参数不正确!");
}
catch(string e)
{
cout<<e<<endl;
return 1;
}
return 0;
}

1. 另外如果程序中抛出的异常程序没有处理的话,就会被系统默认的强制捕获器 terminate捕获,Terminate会调用abort函数把程序异常终止掉
原文地址:https://www.cnblogs.com/liuxinls/p/3193338.html