Created
July 24, 2021 14:47
-
-
Save nariaki3551/251f67838f033b96c12d55092b559cec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unistd.h> // getopt | |
int main(int argc, char* argv[]) | |
{ | |
int a = 0; | |
int b = 0; | |
bool c = false; | |
// first argument parsing | |
int opt; | |
for(int i = 0; i < argc; i++) std::cout << argv[i] << std::endl; | |
while((opt=getopt(argc,argv,"a:c"))!=-1) | |
{ | |
switch(opt) | |
{ | |
case 'a': | |
a = atoi(optarg); | |
break; | |
case 'c': | |
c = true; | |
break; | |
} | |
} | |
// second argment parsng | |
for(int i = 0; i < argc; i++) std::cout << argv[i] << std::endl; | |
optind = 1; | |
while((opt=getopt(argc,argv,"a:b:c"))!=-1) | |
{ | |
switch(opt) | |
{ | |
case 'a': | |
a = atoi(optarg); | |
break; | |
case 'b': | |
b = atoi(optarg); | |
break; | |
case 'c': | |
c = true; | |
break; | |
} | |
} | |
std::cout << "a = " << a << std::endl; | |
std::cout << "b = " << b << std::endl; | |
std::cout << "c = " << c << std::endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment