The problem is that vectors, like arrays, are zero-indexed - if you have k
elements, they are indexed from 0
to k - 1
.
Thus, Deposits[contor]
is out of range for the vector, since it has contor
elements.
(You're lucky that you built a debug version that checks the indexing and found out quickly.)
You could fix this by writing Deposits[contor-1]
, but you have another issue.
That issue is that you're using .eof()
as a loop condition.
eof()
does not mean what you think it means, and you will store one element too many.
(See this Q&A for details.)
The "default" C++ input loop looks like
std::vector<DepositCustomers> Deposits;
std::ifstream fin("in.txt");
DepositCustomers customer;
while (fin >> customer)
{
Deposits.push_back(customer);
}
And a loop-free version is
std::vector<DepositCustomers> Deposits;
std::ifstream fin("in.txt");
using iterator = std::istream_iterator<DepositCustomers>;
std::copy(iterator(fin), iterator(), std::back_inserter(Deposits));