Originally Posted by
Onions
Well, the code now looks like this...
Code:
ifstream file_to_read("DEAD.txt");
string chromosome_string_read;
chromosome_string_read = "";
string fitness_string_read;
fitness_string_read = "";
while (getline(file_to_read, chromosome_string_read, '_') && getline(file_to_read, fitness_string_read)) {
chromosome_string_array.push_back(chromosome_string_read);
fitness_string_array.push_back(fitness_string_read);
}
file_to_read.close();
But it still crashes.
Any thoughts?
Your while loop is still overflowing past the end of your istream (you use getline() twice.
try the following
Code:
while (file_to_read)
std::string s;
std::string::size_type start(0), index;
std::getline(file_to_read, s);
index = s.find('_');
// find character '_' in s
// Error checking to make sure index is valid should go here
std::string chromosome_read(s, start, index);
// chromosome_read initialised with, at most, 'index' number of
// characters taken from s, starting from s[start]
std::string fitness_read(s, index);
// fitness_read is initialised by the characters from s
// starting from s[index]