Name: Anonymous 2011-09-26 18:08
This problem is giving me a headache. I need to read in a file into a 2D vector that looks like this.
data data # data data # data data # #
data data # data data # data data # #
#
I am using a function that only reads until a # is encountered, then it is supposed to store whatever came before it in the vector, and return a boolean true (because the first string read in was not a # sign). If a # is read in as the first string, it returns false, the end of the line, at which point I would advance one row and then continue reading in the next row. Two false returns in a row signals the end of file.
I have that part working correctly. What is not working is actually storing the string into the 2D array.
s.clear(); // s is passed by reference and cleared each time
string temp;
infile >> temp;
while (temp.compare("#"))
{
s.append(temp); // append temp to s
temp.clear(); // clear temp to be read in again
infile >> temp;
}
Right, ok, so s holds the data I want to store into my 2D array. Simply using it like 2d_vector[0][0] = s; obviously doesn't work.
2d_vector.push_back(s); doesn't work either.
Any insight would be appreciated.
data data # data data # data data # #
data data # data data # data data # #
#
I am using a function that only reads until a # is encountered, then it is supposed to store whatever came before it in the vector, and return a boolean true (because the first string read in was not a # sign). If a # is read in as the first string, it returns false, the end of the line, at which point I would advance one row and then continue reading in the next row. Two false returns in a row signals the end of file.
I have that part working correctly. What is not working is actually storing the string into the 2D array.
s.clear(); // s is passed by reference and cleared each time
string temp;
infile >> temp;
while (temp.compare("#"))
{
s.append(temp); // append temp to s
temp.clear(); // clear temp to be read in again
infile >> temp;
}
Right, ok, so s holds the data I want to store into my 2D array. Simply using it like 2d_vector[0][0] = s; obviously doesn't work.
2d_vector.push_back(s); doesn't work either.
Any insight would be appreciated.