mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-09 20:33:39 -04:00
changed test1 and now catching exceptions by ref
This commit is contained in:
parent
74353f79f4
commit
3e2753528f
@ -1,5 +1,4 @@
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <tclap/CmdLine.h>
|
||||
@ -21,25 +20,27 @@ int main(int argc, char** argv)
|
||||
cmd.add( nameArg );
|
||||
|
||||
// Define a switch and add it to the command line.
|
||||
SwitchArg caseSwitch("u","upperCase","Print in upper case", false);
|
||||
cmd.add( caseSwitch );
|
||||
SwitchArg reverseSwitch("r","reverse","Print name backwards", false);
|
||||
cmd.add( reverseSwitch );
|
||||
|
||||
// Parse the args.
|
||||
cmd.parse( argc, argv );
|
||||
|
||||
// Get the value parsed by each arg.
|
||||
string name = nameArg.getValue();
|
||||
bool upperCase = caseSwitch.getValue();
|
||||
bool reverseName = reverseSwitch.getValue();
|
||||
|
||||
// Do what you intend too...
|
||||
if ( upperCase )
|
||||
transform(name.begin(),name.end(),name.begin(),::toupper);
|
||||
if ( reverseName )
|
||||
{
|
||||
reverse(name.begin(),name.end());
|
||||
cout << "My name (spelled backwards) is: " << name << endl;
|
||||
}
|
||||
else
|
||||
transform(name.begin(),name.end(),name.begin(),::tolower);
|
||||
cout << "My name is: " << name << endl;
|
||||
|
||||
cout << "My name is " << name << endl;
|
||||
|
||||
} catch (ArgException e) // catch any exceptions
|
||||
} catch (ArgException &e) // catch any exceptions
|
||||
{ cerr << "error: " << e.error() << " for arg " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ void parseOptions(int argc, char** argv)
|
||||
for ( int i = 0; (unsigned int)i < v.size(); i++ )
|
||||
cout << i << " " << v[i] << endl;
|
||||
|
||||
} catch ( ArgException e )
|
||||
} catch ( ArgException& e )
|
||||
{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ void parseOptions(int argc, char** argv)
|
||||
for ( int i = 0; (unsigned int)i < v.size(); i++ )
|
||||
cout << "[ ] " << i << " " << v[i] << endl;
|
||||
|
||||
} catch ( ArgException e )
|
||||
} catch ( ArgException& e )
|
||||
{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ void parseOptions(int argc, char** argv)
|
||||
_boolTestA = atest.getValue();
|
||||
|
||||
|
||||
} catch ( ArgException e )
|
||||
} catch ( ArgException& e )
|
||||
{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ void parseOptions(int argc, char** argv)
|
||||
throw("still bad");
|
||||
|
||||
|
||||
} catch ( ArgException e )
|
||||
} catch ( ArgException& e )
|
||||
{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ int main(int argc, char** argv)
|
||||
for ( int i = 0; i < num; i++ )
|
||||
cout << "My name is " << name << endl;
|
||||
|
||||
} catch (ArgException e) // catch any exceptions
|
||||
} catch ( ArgException& e) // catch any exceptions
|
||||
{ cerr << "error: " << e.error() << " for arg " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ int main(int argc, char** argv)
|
||||
cout << "Got name " << name[i] << endl;
|
||||
|
||||
|
||||
} catch (ArgException e) // catch any exceptions
|
||||
} catch (ArgException& e) // catch any exceptions
|
||||
{ cerr << "error: " << e.error() << " for arg " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ void parseOptions(int argc, char** argv)
|
||||
for ( int i = 0; (unsigned int)i < v.size(); i++ )
|
||||
cout << "[ ] " << i << " " << v[i] << endl;
|
||||
|
||||
} catch ( ArgException e )
|
||||
} catch ( ArgException& e )
|
||||
{ cout << "ERROR: " << e.error() << " " << e.argId() << endl; }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user