Here's an excerpt from my code:
When I call this function the first time, sure enough it reads in the textfile as I want. The next time I call this function, with a different textfile it only reads in blanks. It doesn't pick up any newlines or anything else.Code:void SparseMatrix2D::read(std::string filename) { std::ifstream inp, in; in.open(filename.c_str(), std::ios::in); if(in.is_open()) { std::vector<double> cols; while(! in.eof() ) { char c; in.get(c); if(c == '\n') { matrix.push_back(cols); while(cols.size() > 0) cols.erase(cols.begin()); } else { double d; in >> d; cols.push_back(d); } } in.clear(); in.close(); } else { std::cout << "file: " << filename << " could not be opened." << std::endl; } }
The textfiles haven't been corrupted or modified in anyway either.
Any help?


Reply With Quote

Bookmarks