1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <fstream>
#include <iostream>
#include <list>
#include <editedstring.h>
using namespace std;
list<EditedString> splitlist(EditedString,char);
void arraysplit(EditedString*, EditedString, char, int);
int main()
{
EditedString path = ("...");
char separator = '\n';
EditedString str;
ifstream ifile(path.c_str());
if (ifile.is_open())
{
// do stuff
}
else
cout << "problem";
int dummy;
cin >> dummy;
return 0;
}
//first function which I want to put in the subclass: splitting strings into lists
list<EditedString> listsplit(EditedString str_in, char sep_in)
{
list<EditedString> splitlist;
int pos = 0, length;
while(str_in.find(sep_in, pos)!=EditedString::npos)
{
length = str_in.find(sep_in, pos) - pos;
splitlist.push_back(str_in.substr(pos, length));
pos += length + 1;
}
splitlist.push_back(str_in.substr(pos,str_in.size())); //what rests after the last separator
return splitlist;
}
//second function which I want to put in the subclass: splitting strings into arrrays
void arraysplit(EditedString* str_array_in, EditedString str_in, char sep_in, int array_length)
{
int pos = 0, ind3x = 0, substr_length;
while((str_in.find(sep_in, pos)!=EditedString::npos) && ind3x < array_length)
{
substr_length = (str_in.find(sep_in, pos) - pos);
str_array_in[ind3x] = str_in.substr(pos, substr_length);
pos += substr_length + 1;
ind3x++;
}
if (ind3x < array_length)
str_array_in[ind3x] = str_in.substr(pos,str_in.size()); //what rests after the last separator
}
|