当前位置: 首页>>代码示例>>C++>>正文


C++ CommandLine::ExtractBegin方法代码示例

本文整理汇总了C++中CommandLine::ExtractBegin方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandLine::ExtractBegin方法的具体用法?C++ CommandLine::ExtractBegin怎么用?C++ CommandLine::ExtractBegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandLine的用法示例。


在下文中一共展示了CommandLine::ExtractBegin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char *argv[])
{
    try
    {
        bool a = false;
        bool nocreate = false;
        string date;
        bool f = false;
        bool m = false;
        string reference;
        string t;
        bool help = false;
        bool version = false;
        string fn;

        CommandLine cl;

        cl.AddSpec ("",          'a', a,
            "change only the access time");
        cl.AddSpec ("no-create", 'c', nocreate,
            "do not create any files");
        cl.AddSpec ("date",      'd', date,
            "parse STRING and use it instead of current time", "STRING","");
        cl.AddSpec ("",          'f', f,
            "(ignored)");
        cl.AddSpec ("",          'm', m,
            "change only the modification time");
        cl.AddSpec ("reference", 'r', reference,
            "use this file's times instead of current time", "FILE", "");
        cl.AddSpec ("",          't', t,
            "use [[CC]YY]MMDDhhmm[.ss] instead of current time", "", " STAMP");
        cl.AddSpec ("help",      '\0',  help,
            "display this help and exit");
        cl.AddSpec ("version",   '\0',  version,
            "output version information and exit");
        cl.AddSpec ("",          '\0',  fn,
            "Target file", "FILE...");

        // Group argv's into option groups
        try
        {
            cl.GroupArgs (argc, argv, 1);
        }
        catch (const exception &e)
        {
            cerr << e.what () << endl;
            cerr << "Usage: " << argv[0] << " " << cl.Usage () << endl;
            cerr << "Try `" << argv[0] << " --help' for more information" << endl;
            return -1;
        }

        // Convert from strings to their proper type
        cl.ExtractBegin ();
        cl.Extract (a);
        cl.Extract (nocreate);
        cl.Extract (date);
        cl.Extract (f);
        cl.Extract (m);
        cl.Extract (reference);
        cl.Extract (t);
        cl.Extract (help);
        cl.Extract (version);
        cl.Extract (fn);
        cl.ExtractEnd ();

        if (help)
        {
            cout << "Usage: " << argv[0] << " [OPTION]... FILE..." << endl;
            cout << "Mimic command line options of the program 'touch'." << endl << endl;
            cout << "Mandatory arguments to long options are mandatory for short options too." << endl;
            cout << cl.Help ("  ", 23) << endl;
            cout << "Note that the -d and -t options accept different time-date formats." << endl << endl;
            cout << "If a FILE is -, touch standard output." << endl << endl;
            cout << "Report bugs to <[email protected]>." << endl;
            return 0;
        }

        if (version)
        {
            cout << "version 1.0.0" << endl;
            return 0;
        }

        if (fn.empty ())
        {
            cerr << argv[0] << ": missing file operand" << endl;
            cerr << "Try `" << argv[0] << " --help' for more information" << endl;
            return -1;
        }

        cout << "a: " << a << endl;
        cout << "nocreate: " << nocreate << endl;
        cout << "date: " << date << endl;
        cout << "f: " << f << endl;
        cout << "m: " << m << endl;
        cout << "reference: " << reference << endl;
        cout << "t: " << t << endl;
        cout << "FILE[0]: " << fn << endl;
        vector<string> leftover_args = cl.GetLeftOverArgs ();
        for (unsigned i = 0; i < leftover_args.size (); ++i)
//.........这里部分代码省略.........
开发者ID:jeffsp,项目名称:argv,代码行数:101,代码来源:touch_example.cpp


注:本文中的CommandLine::ExtractBegin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。