So, in the spirit of full disclosure, this is actually part of a project that I have to do for a class for school. However, I'm hoping that someone with a little more C++ experience than I might be able to help me, because I've gotten pretty stuck.
Essentially, I have a vector, which I'm passing by reference to another object, which is supposed to print out part of the vector. Even when I just try to print the first element in the vector, however, if gives me a "std::out_of_range" error. But when I check the size of the vector right before that, it correctly returns that the size of the vector is two, so there must be an element in the 0th position, right? This code:
if (attributeList.empty()){
out << "Empty!" << endl;
} else {
out << "Not empty!" << endl;
out << "Vector size: " << attributeList.size() << endl;
out << attributeList.at(0) << endl;
}
prints out:
Not empty!
Vector size: 2
A
"A" is the element contained in the 0th slot of the vector, and it is correctly printing out, so why is it throwing an error here?
This isn't really urgent, but it certainly has me pretty baffled. Can anyone think of why this might be happening?