常海龙的blog

A day is a miniature of eternity

用户操作
[即时聊天] [发私信] [加为好友]
常海龙ID:hailongchang
31544次访问,排名3741好友0人,关注者23
hailongchang的文章
原创 45 篇
翻译 0 篇
转载 0 篇
评论 11 篇
常海龙的公告
Locations of visitors to this page


最近在读...

最近评论
c123456603:呀,有源码嘛?
clarke:不错, 顶一个.
coolhu:好东西,值得研究一下
accesine960:正要用到
Infinite:看看这个.

http://www.timeearth.com

就包含了虚拟桌面了.
文章分类
收藏
    相册
    blog configuration
    Linux&Unix
    兰州大学开源社区
    Mathematics
    Mathematica Tutorial
    博士家园论坛
    Programming
    CodeProject
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 一个带命令行解析功能的console程序框架收藏

    新一篇: 手工打造一个QQ空间备份工具 | 旧一篇: 一个命令行参数解析器

              这个程序的代码对于很多linux程序员应该是很熟悉的,仿照linux实现了命令行参数解析器,所以提供一个框架程序,以后再写类似代码的时候直接在本框架的基础上修改就是了。
    #include "GetOpt.h"
    
    #include<iostream>
    
    
    
    using namespace std;
    
    
    
    const char* program_name;
    
    
    
    void print_usage ()
    
    {
    
    
    
        cout << "Usage: %s options [outputfile ...]" << endl;
    
    
    
        cout << " -h --help Display this usage information." << endl;
    
        cout << " -o --output filename Write output to file." << endl;
    
        cout << " -v --verbose Print verbose messages." << endl;
    
    
    
    }
    
    
    
    int main (int argc, char* argv[])
    
    {
    
        int opt;
    
      
    
        const char* const short_options = "ho:v";
    
    
    
        const struct option long_options[] = {
    
            { "help",         no_argument,          NULL,   'h' },
    
            { "output",     required_argument,  NULL,   'o' },
    
            { "verbose",   no_argument,          NULL,   'v' },
    
            { NULL,         no_argument,           NULL,   0 }
    
        };
    
    
    
        int verbose = 0;
    
    
    
        program_name = argv[0];
    
    
    
        opt = getopt_long (argc, argv, short_options,long_options, NULL);
    
    
    
        if(opt == -1)
    
        {
    
            print_usage();
    
            exit(0);
    
        }
    
        while(opt != -1)
    
        {
    
            switch (opt)
    
            {
    
                case 'o':
    
                    cout << "outputfile is: " << optarg << endl; 
    
                    break;
    
    
    
                case 'v': 
    
                    cout << "print verbose infomation" << endl;
    
                    break;
    
    
    
                case '?':
    
                    cout << "sytax error: no this argument: " << static_cast<char>(optopt) << endl;
    
                    print_usage();
    
                    exit(0);
    
    
    
                case 'h': 
    
                    print_usage ();
    
                    break;
    
    
    
                default: 
    
                    break;
    
            }
    
            opt = getopt_long (argc, argv, short_options,long_options, NULL);
    
        }
    
    
    
        return 0;
    
    }

    发表于 @ 2008年06月20日 11:11:13|评论(loading...)|收藏

    新一篇: 手工打造一个QQ空间备份工具 | 旧一篇: 一个命令行参数解析器

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 常海龙