参数解析

#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]!=''; i++)
    {
        if(str[i]==' ' || str[i]=='	' )
        {
            if(i>0 && str[i-1]!=' ')
            {
                tmp[tmpcount] = '';
                tmpcount = 0;
                string stmp = tmp;
                v.push_back(stmp);
            }
        }
        else
        {
            tmp[tmpcount++] = str[i];
        }
    }
    if(tmpcount>0)
    {
        tmp[tmpcount]='';
        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,'
');

    solve(buf);


    return 0;
}

  

原文地址:https://www.cnblogs.com/hardsoftware/p/6235068.html