#include <windows.h>
#include <tchar.h>
#if 0
typedef struct _MYCMD
{
TCHAR *Cmd[20] = { 0 };
int nLen = 0;
}MYCMD, *LPMYCMD;
MYCMD GetCmdLine(TCHAR *CmdLine)
{
TCHAR seps[] = _T(" ,\t\n");
TCHAR *token1 = NULL;
TCHAR *next_token1 = NULL;
token1 = _tcstok_s(CmdLine, seps, &next_token1);
MYCMD cmd;
do
{
if (token1 != NULL)
{
cmd.Cmd[cmd.nLen] = token1;
token1 = _tcstok_s(NULL, seps, &next_token1);
cmd.nLen++;
}
} while (token1 != NULL && cmd.nLen < 20);
return cmd;
}
#endif
// 获取命令行参数,最多可获取20个
class MyCMD
{
public:
MyCMD(TCHAR *szCMD);
TCHAR **Get();
~MyCMD();
TCHAR *Cmd[20] = { 0 };
int nLen = 0;
private:
TCHAR *szCmd = NULL;
};
MyCMD::MyCMD(TCHAR *szCMD)
{
int size = _tcsclen(szCMD) * sizeof(TCHAR) + sizeof(TCHAR);
this->szCmd = new TCHAR[size]{ 0 };
memcpy_s(szCmd, size, szCMD, size);
}
TCHAR
C/C++/VC++ 命令行参数解析
最新推荐文章于 2023-05-11 14:24:04 发布