Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Тестовые примеры / ch4 / test_getopt
.C #include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char* outfile;
static int a_flag, b_flag;
int main( int argc, char* argv[] )
{
int ch;
while ( (ch=getopt( argc, argv,"o:ab" )) != EOF )
switch ( ch ) {
case 'a': a_flag = 1; // found -a
break;
case 'b': b_flag = 1; // found -b
break;
case 'o': outfile = new char[strlen(optarg)+1];
strcpy(outfile,optarg); // found -o <file>
break;
case '?': /* let getopt flags an eror message */
default: break; // an illegal switch
}
/* no more switches. Scan the rest of non-switch arguments */
for ( ; optind < argc; optind++ )
cout << " non-switch argument: " << argv[optind] << endl;
return 0;
}
Соседние файлы в папке ch4