作者dozer (rezod)
看板LinuxDev
标题Re: [问题] 写 --help 功能
时间Tue Jun 12 17:58:00 2007
※ 引述《ephesians (ephesians)》之铭言:
: 写命令参数(例如 --help)的时候,发现一开始若不先想好各种情况,
: 写好一点架构的时候,如果想再改一点点,可能会让原有的架构破局.
: (因为半成品嘛,改来改去正常)
: 不过每改一次,每一种情况都要重新测试一次,蛮累的,
: 有没有比较容易增删的程式写法呢?
: 我的写法是
: for (i=0; i<argc; i++) {
: if (strcmp(*(argv+i), "-h") == 0) {
: cout << "Usage: " << *argv << " [-h] [-t] [-p]" << endl;
: } else if ( ... ) {
: ...
: }
: }
看你的语法好像是想用C++,为什麽不用C++的string class呢?
C/C++混着写感觉好像会很混乱.......
另外,对於argument的处理,GNU C Library有提供一些很好用的工具
可以参考
http://www.gnu.org/software/libc/manual/html_node/Parsing-Program-Arguments.html
--
The inherent vice of capitalism is the unequal sharing of blessings;
the inherent virtue of socialism is the equal sharing of misery.
-- Churchill
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.109.176.149
1F:推 ephesians:这不算混着写吧.. 06/16 02:12