我想确保 -f 之后的选项/参数是 0-9 之间的数字。总共必须有 10 个参数,顺序不限。唯一的条件是 -f 后面必须跟一个数字。
/* Ensure that the -f option is included in the arguments
and it is preceeded by valid digit between 0 -9 */
int Crypto::offsetValidation( int argc, char *argv[] )
{
for( int i = 0; i < argc; i++ )
{
if(argv[i] == string("-f"))
{
cout << "offset" << endl;
return offset;
}
}
cout << "Usage: -f is required for offset" << endl;
exit(EXIT_FAILURE);
return 0;
}