2011/08/16

[c++]簡易剖析範例

#include <iostream>
#include <stdlib.h>

using namespace std;

void Parse(string source,string key)
{
    string Temp = "";
    source = source + key;

    for(int i=0; i<source.length(); i++)
    {
        if(source[i]!= key[0])
        {
            Temp = Temp + source[i];
        }
        else
        {
            cout << Temp << endl;
            Temp = "";
        }
    }
}
int main()
{
    string str;
    string keyword;

    cout << "Please input str:";
    getline(cin,str);
    cout << "Please input keyword:";
    getline(cin,keyword);
    cout << "Parse Result:" << endl;
    Parse(str,keyword);

    return 0;
}