All pastes #716640 Raw Edit

Untitled

public cpp v1 · immutable
#716640 ·published 2007-09-27 00:44 UTC
rendered paste body
   1.      #include <iostream>   2.      #include <string>   3.      #include <vector>   4.      using namespace std;   5.      /* Method that takes two parameters, a string and a char delimeter, respectivly and returns a vector containing all the parts broken into parts by the delimeter.*/   6.      vector<string> split(const string original, char delimeter);   7.      int main()   8.      {   9.      while (1  10.      {  11.      char ch = ' ';  12.      string str = "";  13.      cout<<"String: "<<endl;  14.      getline(cin, str, '\n');  15.      cout<<"Delimeter(char, s for space): ";  16.      cin>>ch; cin.ignore(); ch = (ch == 's') ? ' ' : ch;  17.      vector<string> res = split(str, ch);  18.      cout<<endl<<endl<<"Split String:"<<endl;  19.      for (int i(0); i < res.size(); i++  20.      {  21.      cout<<i<<" :"<<res[i]<<endl;  22.      }  23.      res.clear();  24.      }  25.      cin.get();  26.      return 0;  27.      } //end main  28.      vector<string> split(const string original, char delimeter)  29.      { //Store the temporary results in a vector and then transfer to an  30.      vector<string> returnVector;  31.      string curr = "";  32.      if (original.size() < 2) return returnVector;  33.      for (int itr(0); itr < original.size(); itr++)  34.      {  35.      if (original[itr] != delimeter)  36.      {  37.      while ( original[itr] != delimeter && itr != original.size() )  38.      {  39.      curr += original[itr++];  40.      }  41.      returnVector.push_back(curr);  42.      curr = "";  43.      } //end check for first match (ie not delim found)  44.      } //End loop of string  45.      return returnVector;  46.      } //end function