No operator << matches these operands

I’ve been reading questions here for an hour or two regarding this error I’m getting and most of them forgot to #include string (which I had already done), or to overload the << operator. Here’s the code in question: And the error I’m getting: All I’m trying to do is return the vector. I read … Read more

Insert object at index of vector c++

The straight forward answer is you need an iterator. The iterator for std::vector supports random access, which means you can add or subtract an integer value to or from an iterator. The better answer is don’t use an index, use an iterator. What is your loop? You should be able to refactor the loop to … Read more

How to iterate over a vector?

If you have access to C++11 you can use range-based for loops Otherwise you should use begin() and end() You can also use std::begin and std::end (these require C++11 as well) begin will return an iterator to the first element in your vector. end will return an iterator to one element past the end of your vector. So the order in which you get the elements iterating … Read more

Why use a new call with a C++ ‘vector’?

Your first statement is not true. The elements in vector<someType> myVector will live until the vector is destroyed. If vector<someType> is a local variable, it will be destroyed automatically when it goes out of scope. You don’t need to call delete explicitly. Calling delete explicitly is error-prone if you take into account that because of exceptions that might be thrown, your delete statement … Read more