Undefined
By: Guest | Date: Oct 6 2010 18:35 | Format: C++ | Expires: never | Size: 1.25 KB | Hits: 853
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- vector<string> explode( const string &delimiter, const string &explodeme);
- int main(int argc, char *argv)
- {
- string fileName = "accounts.txt";
- ifstream inFile(fileName.c_str());
- string fileData((istreambuf_iterator < char> (inFile)), istreambuf_iterator < char> ());
- vector<string> v = explode("n", fileData);
- for(int i=0; i<v.size(); i++)
- {cout << v[i] <<endl;}
- cin.get();
- return 0;
- }
- vector<string> explode( const string &delimiter, const string &str)
- {
- vector<string> arr;
- int strleng = str.length();
- int delleng = delimiter.length();
- if (delleng==0)
- return arr;//no change
- int i=0;
- int k=0;
- while( i<strleng )
- {
- int j=0;
- while (i+j<strleng && j<delleng && str[i+j]==delimiter[j])
- j++;
- if (j==delleng)//found delimiter
- {
- arr.push_back( str.substr(k, i-k) );
- i+=delleng;
- k=i;
- }
- else
- {
- i++;
- }
- }
- arr.push_back( str.substr(k, i-k) );
- return arr;
- }
Latest pastes
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago