Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,210 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 904 people online right now. Registration is fast and FREE... Join Now!




My Vectors Won't Show

 
Reply to this topicStart new topic

My Vectors Won't Show

ifsogirl
post 15 Mar, 2008 - 04:26 AM
Post #1


New D.I.C Head

*
Joined: 15 Mar, 2008
Posts: 18


My Contributions


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
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 15 Mar, 2008 - 05:17 AM
Post #2


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


OK, you're gonna kick yourself for this:

The first try was pretty much right, there was only one thing that you missed in it:
you wrote for(int x; x<wbag.size(); x++)

All you forgot to do was initialise x: for(int x=0; x<wbag.size(); x++)
User is offlineProfile CardPM

Go to the top of the page

ifsogirl
post 15 Mar, 2008 - 05:21 AM
Post #3


New D.I.C Head

*
Joined: 15 Mar, 2008
Posts: 18


My Contributions


Oh Jashin!
Thank you so much. God, I'm such an idiot. Thank you so so so much. I only have a few days left before this is due and I'm stuck on this. You are awesome; I can't thank you enough.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 07:55PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month