全部:不知道如何使用彈出庫
感謝您的幫助。
我是新來的C選項解析,現在,我想要的是使用popt庫來解析每個參數,並prnit出來。
#include <iostream>
#include <string>
#include <cstring>
#include <popt.h>
using namespace std;
int main(int argc, const char* argv[]){
char* dt1;
char* dt2;
struct poptOption {
const char * longName; /* may be NULL */
char shortName; /* may be ’\0’ */
int argInfo;
void * arg; /* depends on argInfo */
int val; /* 0 means don’t return, just update flag */
char * descrip; /* description for autohelp -- may be NULL */
char * argDescrip; /* argument description for autohelp */
};
struct poptOption optionsTable[]={
{"start",'s',POPT_ARG_STRING,dt1,'s',"The date format should like YYYY-MM-DD.",0},
{"end",'e',POPT_ARG_STRING,dt2,'e',"The date format should like YYYY-MM-DD.",0},
//~ POPT_AUTOHELP
//~ {NULL,0,0,NULL,0}
};
poptContext optCon;
optCon = poptGetContext (0, argc, argv, optionsTable, 0);
const char* portname = poptGetArg(optCon);
cout<<portname<<endl;
return 0;
}
當我編譯它,我得到了錯誤llike:
test.cpp: In function ‘int main(int, const char**)’
test.cpp:27: warning: deprecated conversion from string constant to ‘char*’
test.cpp:27: warning: deprecated conversion from string constant to ‘char*’
test.cpp:30: error: cannot convert ‘main(int, const char**)::poptOption*’ to ‘const poptOption*’ for argument ‘4’ to ‘poptContext_s* poptGetContext(const char*, int, const char**, const poptOption*, unsigned int)’
謝謝!克雷格,我明白了。 – Kuan 2013-03-27 16:12:01