C++ 代码生成器

这里写图片描述

代码:

https://github.com/pangPython/cpp_code_gen

readme

  • 使用
    先编译:make
    再运行:./ctgen hello.cpp
    可以清除:make clean

  • 注释:作者、时间

  • demo

#include <iostream>
/******************************
 * author:py
 * time:2017-06-30 21:48:33 Friday
 *
*****************************/
using namespace std;
int main()
{

}

main.cpp

#include <iostream>
#include <fstream>
#include <ctime>
#include <unistd.h>
/**************************
 *
 *通过命令行生成cpp文件模板
 *
 *
 *
 **************************/
using namespace std;

int main(int argc,char *argv[])
{
    //判断命令行参数个数
    if(argc <= 1){
        return 1;
    }
    //获取文件名
    char *filename = argv[1];
    //创建文件
    ofstream out(filename);
    //获取当前系统时间
    time_t now_time = time(0);
    char tmp[64];
    strftime(tmp,sizeof(tmp),"%Y-%m-%d %X %A",localtime(&now_time));

    //把代码写入文件
    out << "#include <iostream>" << endl;
    out << "/******************************" << endl;
    out << " * author:" << getlogin() << endl;//获取当前*nix系统的当前用户名
    out << " * time:"  << tmp << endl;
    out << " *" << endl;
    out << "*****************************/" << endl;
    out << "using namespace std;" << endl;
    out << "int main()" << endl;
    out << "{" << endl;
    out << endl;
    out << "}" << endl;

    return 0;
}

makefile

SRC=./src/
all:ctgen
ctgen:$(SRC)main.cpp
    g++ $(SRC)main.cpp -o ctgen
clean:
    rm ctgen
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值