本文整理汇总了C++中tokenizer::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ tokenizer::begin方法的具体用法?C++ tokenizer::begin怎么用?C++ tokenizer::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tokenizer
的用法示例。
在下文中一共展示了tokenizer::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//=========================MAIN FUNCTION=======================
int main(int argc,char **argv){
string home = getenv("HOME");
string dir;
//char cwd[BUFSIZ];
//Loginv
char host[200];//allocate memeory for host
char* user;
int hStat = gethostname(host, 200);
if(hStat !=0){
perror("Cannot get Host Name");
}
if(getlogin() != NULL){
user = getlogin();
}else{
perror("Cannot get User Name");
}
struct sigaction newAction, oldAction;
newAction.sa_handler = sigHandler;
sigemptyset(&newAction.sa_mask);
newAction.sa_flags = 0;
//For handeling ^C and such
if(oldAction.sa_handler != SIG_IGN){
if(sigaction(SIGINT, &newAction, &oldAction )< 0){
perror("sigaction");
}
}
//Declarations
string input;
vector<string> args;
vector<string> tempArgs;
bool comment = false;
//While loop that repeats $ and cin command
while(true){
cout << user << "@" << host << "$ ";
/*if(getcwd(cwd,BUFSIZ) == NULL){
perror("getcwd");
}
dir = cwd;
if(home == "\0"){
perror("getenv");
}
if(dir.find(home,0) != string::npos){
dir.replace(0,home.size(),"~");
}
cout << dir <<"$ ";*/
cout.flush();//flush just to be safe
cin.clear();
comment = false;
getline(cin,input);
//================Tokenize the input into multiple parts==============
char_separator<char> delim(" ",";#>|&");
tokenizer<char_separator<char> > mytok(input, delim);//seperat the input
for(mytok::iterator it = mytok.begin(); it != mytok.end(); ++it){
//cout << "token: " << *it << endl;
if(*it == "exit"){
exit(0);
}else if(*it == "#"){
comment = true;
}else if(!comment){
args.push_back(*it);
}
}
concatArg(args);
//==============RUN THE COMMANDS======================
/*for(unsigned int j=0; j<args.size();++j){
cout << args[j] << endl;
} DEBUG PURPOSES*/
if(properInput(args)){
for(unsigned int i=0 ; i<args.size();++i){
if(args[i]==";"){
singleCommand(tempArgs);
tempArgs.clear();
}else if(args[i]!="&&" && args[i]!="||"){
tempArgs.push_back(args[i]);
}else if(args[i]=="||"){
if(!singleCommand(tempArgs)){
tempArgs.clear();
break;
}
tempArgs.clear();
}else if(args[i]=="&&"){
if(singleCommand(tempArgs)){
tempArgs.clear();
break;
}
tempArgs.clear();
}
}
singleCommand(tempArgs);
tempArgs.clear();
}
args.clear();
//.........这里部分代码省略.........