-
December 5th, 2011, 12:34 PM
#1
Reading my textfile as blank
Here's an excerpt from my code:
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;
}
}
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.
The textfiles haven't been corrupted or modified in anyway either.
Any help?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|