参数解析
Posted Hardsoftware
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了参数解析相关的知识,希望对你有一定的参考价值。
#include<iostream> #include<vector> #include<string> using namespace std; void solve(char *str) { vector<string> v; char tmp[100]; int tmpcount = 0; for(int i=0; str[i]!=‘\0‘; i++) { if(str[i]==‘ ‘ || str[i]==‘\t‘ ) { if(i>0 && str[i-1]!=‘ ‘) { tmp[tmpcount] = ‘\0‘; tmpcount = 0; string stmp = tmp; v.push_back(stmp); } } else { tmp[tmpcount++] = str[i]; } } if(tmpcount>0) { tmp[tmpcount]=‘\0‘; string stmp = tmp; v.push_back(stmp); } cout<<v.size()<<endl; for(int i=0; i<v.size(); i++) cout<<v[i]<<endl; } int main() { char buf[100]; cin.get(buf,100,‘\n‘); solve(buf); return 0; }
以上是关于参数解析的主要内容,如果未能解决你的问题,请参考以下文章