You can think of an iterator as a pointer that always points to some element in some container. Incrementing it will make it point to the next element. Every container in the STL has a begin() and an end() member functions, which return iterators to the first element and to one past the last element, respectively. Looping like this:
1 2 3 4 5 6
// foo is a container of type std::some_container
for(std::some_container::iterator it = foo.begin(); it != foo.end(); ++it)
{
// whatever
}
will cause the loop to iterate over every element in that container. Note that not every container allows accessing elements using an index, so iterators are the only way to iterate over every element in a way that will work with any STL container.
Global.h
extern vector<string> inventory; // to allow ay cpp to access it at any time
//________________________________________________________________________
Cabin.cpp
vector<string> inventory; //to initiallize
inventory.push_back("Metal Bar"); // to add to the inventory
//________________________________________________________________________
as well for when i am checking to see if it is there for a result that requires me to have the
item
bool Check_Inv(string check)
{
for (int i = 0; i < inventory.size();i++)
{
string item = inventory [i]
if (item == check)
returntrue;
}
returnfalse;
}
algorithm is opart of the std_lib_facilities.h that is in my library.h
and i wasn't sure what to type since you used std:: which with the std_lib_facilities and the fact that i have also put usingnamespace std in the library.h as well
Bringing the entire standard library to the global namespace doesn't stop you from fully qualifying identifiers (saying std::).
One thing you should never do is put usingnamespace std; inside a header file. You also shouldn't use std_lib_facilities.h, which is a header file from Stroustrup's book and, if I remember correctly, uses a macro hack to override the standard library vector. Don't use what you don't need.
If you still need help, post the error messages and I'll have a look.