- 論壇徽章:
- 2
|
本帖最后由 leiing 于 2016-08-09 14:43 編輯
看資料getopt只能解析短參數(shù)的,如-c -o -E,而getopt_long是解析長參數(shù)的,如--help。
但是像-Wall,只有一個橫線,但有多個字符,如何解析?
- int opt = 0;
- static const char *optString = "Il:o:vh?";
- opt = getopt( argc, argv, optString );
- while( opt != -1 ) {
- switch( opt ) {
- case 'I':
- break;
-
- case 'l':
- break;
-
- case 'o':
- break;
-
- case 'v':
- break;
-
- case 'h': /* fall-through is intentional */
- case '?':
- display_usage();
- break;
-
- default:
- /* You won't actually get here. */
- break;
- }
-
- opt = getopt( argc, argv, optString );
- }
-
復(fù)制代碼 謝謝。
|
|