Problems with ifstream -- reading a textfile, but skipping over next one

Here's an excerpt from my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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?
Topic archived. No new replies allowed.