I'm trying to read an input file formatted with two numbers on a line and store the first number in the line in one vector and the second number in another vector.
Every part of my code works fine except for the actual reading of the file.
I have put couts
all over the place and it looks like while my file is being opened, it's not being read, so my vectors keep getting filled until I run out of memory.
Here's the part of my code that reads the file:
cout << "Input Filename: ";
cin >> input;
//open input file
inputdata.open(input.c_str());
if(!inputdata){
cerr << "Error: Unable to open file!" << endl;
}
while(!inputdata.eof()){
counter++;
hold = 0;
if(counter > 0){
inputdata >> hold;
//cout << hold << endl;
if(counter%2 != 0)
data.push_back(hold);
else
weight.push_back(hold);
}
}
(where counter is an integer initialized at -1 since there is a one-word title at the beginning of the input file that I need to ignore).
I know using .eof()
is frowned upon, but it won't actually affect what I'm doing.
Does anyone see a problem in my code or why it wouldn't be reading the file?