Okay, before I go flashing my code up, I'm going to try, in my limited capability, to explain this issue I'm having. I'm trying to code an inventory for a game- I have to use a vector because... I was told to. I preferred the array, but my teacher wants vectors, so fine; I give him vectors. My problem is not with making the vector- I figured that one out okay... but for whatever reason, I can't make my vectors show up, at all, anywhere in my game code. I tried doing it with a for-loop, which was the first method wer were taught.
Tha looks like this:
CODE
//vector for final
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<string> wbag;
wbag.push_back("Lance");
wbag.push_back("Battle Axe");
wbag.push_back("Broad Sword");
wbag.push_back("Mages Herb");
for (int x; x<wbag.size();x++)
{
cout<<wbag[x]<<endl;
}
system("pause");
return 0;
}
It didn't show up. So I tried doing it with a void, which was the second method we were taught. That looked like this:
CODE
vector<string> wbag;
wbag.push_back("Lance");
wbag.push_back("Battle Axe");
wbag.push_back("Broad Sword");
wbag.push_back("Mages Herb");
display (wbag);
cout<<"You Now Have: "<<endl;
display (wbag);
void display (const vector<string>& vec);
{
cout<<"Items in your bag: "<<endl;
for(vector<string>:: const_iterator look= vec.begin();
look !=vec.end(); look++);
{
cout<<*look<<endl;
}
}
I've been sick a lot throughout this class, so I probably missed the lecture on how to do this right. If anyone can help me figure out what I did wrong, please, please do.
-thanks-
This post has been edited by ifsogirl: 15 Mar, 2008 - 04:27 AM