当VC程序需要命令行参数时,参数的获取
方法一:CString str=::GetCommandLine(); 获取命令行
方法二:
void GetArgs(CString &arg1, CString &arg2, CString &arg3)
{
CString commandArgs=AfxGetApp()->m_lpCmdLine;
if (commandArgs.IsEmpty())
{
return;
}
int len=commandArgs.GetLength();
CString temp[3]={L"0"};
for (int i=0,j=0; i<len; i++ )
{
TCHAR ch=commandArgs.GetAt(i);
if (ch == L' ')
{
j++;
continue;
}
else
{
temp[j].AppendChar(ch);
}
}
agr1=temp[1];
agr2=temp[2];
agr3=temp[3];
}