i am reading in data from an input file and sorting it as it comes in. (ive done this before just without sorting so i know everything else works fine.)
StringTable::StringTable(ifstream & infile)
{
// TODO: complete
string s;
vector<string> row;
vector< vector<string> >::iterator srow = table.begin();
vector< vector<string> >::iterator erow = table.end();
vector<vector<string> >::iterator i;
vector<string>::iterator i2;
i=table.begin();
//i2=(*i).begin();
while (readMultiWord(s, infile)) // not end of file
{
row.clear();
do
{
row.push_back(s);
}
while (readMultiWord(s, infile));
if (table.size()==0)
{
table.push_back(row);
}
else
{
vector<string>::iterator news=row.begin();
for (int i=0; i<table.size(); i++)
{
erow = table.end();
cout << "hi..." << endl;
vector<string>::iterator scol = srow->begin();
cout <<"hi..." << endl;
cout << *scol << " " << *news << endl;
if (*scol<*news)
{
table.push_back(vector<string>());
table.insert(srow, row);
cout << *scol << " " << *news << endl;
}
srow++;
}
}
}
}
when i create the iterator scol it is throwing me a seg fault, and i cant seem to figure out why. if anyone could help that would be fantastic.
update: got past the seg fault but now it gets through about three of the names and throughs an error. terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
Abort