Assertion Failure?

My program will compile but while debugging, it gives a an assertion failure. Below is my code. This worked as an array but it will not work with a vector. Am I missing something?

int i = 0;
while(!ins.eof())
{
getline(ins, line);
nums[i] = atof(line.c_str());
cout << nums[i] << endl;
i++;
}

How large is nums?
what is nums? if thats a vector, it will not work this way. you need to use push_back().

or else allocate memory first and then use it the way you are doing.
It is an uninitialized vector. If I use push_back, would it be nums.push_back(i) = atof(line.c_str())?
nums.push_back(atof(line.c_str());
you dont have to give the index, it is going to push at the end.

to access you do this:
float value_at_index_i = nums[i];
Awesome! Thank you.
Topic archived. No new replies allowed.