I am trying to read the arguments in the main with this code, what I need is that, when the arguments are -v
then a = 10
keep this and when they are -g
pass flag a true
, but when I run it with -g send me "file: unknown option - g"
string val;
string name;
bool flag=false;
int c;
while((c=getopt(argc,argv,"vg:")) != -1){
string a;
bool b;
int va;
switch(c){
case 'v':
b=false;
a=optarg;
for (int i=0;i<a.length();i++){
if(a[i]!='='&& b==false)
{
name+=a[i];
}
if(a[i]!='='&& b==true)
{
val+=a[i];
}
if(a[i]=='=')
{
b=true;
}
}
va=atoi(val.c_str());
calc->addVal(name,va);
name.clear();
val.clear();
a.clear();
break;
case 'g':
flag=true;
cout<<flag<<endl;
break;
}
}