文件:http://pan.baidu.com/s/1ntlu14H
// createVSClass.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<string.h>
#include <stdlib.h>
char temp[1024 * 5];
const char * upper(char *t)
{
strcpy(temp, t);
for (unsigned i = 0; i < strlen(temp); i++)
{
if(t[i] >= 'a' && t[i] <= 'z')
{
temp[i] = t[i] - 32;
}
else
{temp[i] = t[i];}
}
return temp;
}
//求子串
char* subStr(const char*str, unsigned long start, unsigned long end)
{
unsigned long n = end - start;
static char stbuf[1024 * 512];
strncpy(stbuf, str + start, n);
stbuf[n] = 0; //字串最后加上0
return stbuf;
}
int _tmain(int argc, _TCHAR* argv[])
{
char path[1024 * 5];
char name[1024 * 5];
printf("请输入类名:");
scanf("%s", name);
printf("请输入路径:");
scanf("%s", path);
char cppPath[1024 * 5];
strcpy(cppPath, path);
if(0 == strcmp(name, "") * strcmp(path, ""))
{return 1;}
//write to .h
if('\\'!= path[strlen(path) - 1])
{strcat(path, "\\");}
strcat(path, name);
strcat(path, ".h");
FILE *fp = fopen(path, "w");
fprintf(fp, "#ifndef _%s_H_\n\
#define _%s_H_\n\n\
#include \"cocos2d.h\"\n\n\
class %s: public cocos2d::CCLayer\n\
{\n \
public:\n \
virtual bool init();\n\n \
static cocos2d::CCScene* scene();\n\n\
CREATE_FUNC(%s);\n\n\
cocos2d::CCSize winSize;\n\
};\n\n\
#endif ", upper(name), upper(name), name, name);
fclose(fp);
//write to .cpp
if('\\'!= cppPath[strlen(cppPath) - 1])
{strcat(cppPath, "\\");}
strcat(cppPath, name);
strcat(cppPath, ".cpp");
fp = fopen(cppPath, "w");
fprintf(fp, "#include \"%s.h\"\n\n\
USING_NS_CC;\n\n\
CCScene* %s::scene()\n\
{\n\
CCScene *scene = CCScene::create();\n\
%s *layer = %s::create();\n\
scene->addChild(layer);\n\
return scene;\n\
}\n\n\
bool %s::init()\n\
{\n\
if ( !CCLayer::init() )\n\
{\n\
return false;\n\
}\n\
winSize = CCDirector::sharedDirector()->getVisibleSize();\n\
return true;\n\
}", name, name, name, name, name);
fclose(fp);
char openStr[1024 * 5];
strcpy(openStr, "start ");
strcat(openStr, cppPath);
system(subStr(openStr, 0, strlen(openStr) - strlen(name) - 4));
return 0;
}