- 论坛徽章:
- 0
|
从命令行中解析出文件名和命令选项
using namespace std;
#include
#include
void PrintIt(string it)
{
cout cmdLineParameter;
list::iterator startOfFiles;
list flags;
list fileNames;
for(int i=0;i<argc;i++)
cmdLineParameter.push_back(argv);
//remove the program name
cmdLineParameter.pop_front();
int numberOfFiles;
numberOfFiles=count_if(cmdLineParameter.begin(),cmdLineParameter.end(),IsAFileName());
cout<<"The "<<(numberOfFiles==4?"correct":"wrong")<<"number("<<numberOfFiles<<")of file names were specified"<<endl;
startOfFiles=stable_partition(cmdLineParameter.begin(),cmdLineParameter.end(),IsAFlag());
cout<<"command line parameter after stable_partition"<<endl;
for_each(cmdLineParameter.begin(),cmdLineParameter.end(),PrintIt);
flags.splice(flags.begin(),cmdLineParameter,cmdLineParameter.begin(),startOfFiles);
if(!flags.empty())
{
cout<<"flags spliced :\n";
for_each(flags.begin(),flags.end(),PrintIt);
}
else
cout<<"No flags specified\n";
fileNames.splice(fileNames.begin(),cmdLineParameter,cmdLineParameter.begin(),cmdLineParameter.end());
if(!fileNames.empty())
{
cout<<"file spliced:\n";
for_each(fileNames.begin(),fileNames.end(),PrintIt);
}
else
cout<<"No filename specified\n";
if(find_if(flags.begin(),flags.end(),IsHelpFlag())!=flags.end())
cout<<"the help flags was specified.\n";
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56374/showart_1279907.html |
|