Archived

This topic is now archived and is closed to further replies.

Vector doesn't work

This topic is 5011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to use vectors in my program and it does not work. I am using Visual c++ creating a win32 program. Also I am including but it still doesn''t work. I get this error e:\3deditor\main.cpp(287) : error C2065: ''vector'' : undeclared identifier

Share this post


Link to post
Share on other sites
try doing a simple using std::vector before you open up int main()

EDIT: Additionally make sure you do #include<vector> at the top

[edited by - nervo on March 25, 2004 9:25:36 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by dr_slash_uh
Thanks, I do not use ansi to much...Sadly embarrased


Sometimes you can do a "using namespace std;" call, but I usually prefer to declare only what functions I''ll use from stl so I don''t declare any custom function that would conflict with something I''m not aware with in namespace std. Personal preference though.

Share this post


Link to post
Share on other sites
How do you assign a reference to a vector. for example:


struct obj
{
int num;
};

int main()
{
obj B;
vector "obj" *pointer;
pointer[0]=B;
}

this does not work? how could I achieve this.

[edit]just replace " with <>

[edited by - dr_slash_uh on March 25, 2004 12:06:42 AM]

Share this post


Link to post
Share on other sites
vector is a template and you have to use it like this:

vector* pointer = new vector;

pointer->push_back(B); // insert at the end




EDIT:There did <> go?

[edited by - OrthoDiablo on March 25, 2004 12:01:22 AM]

Share this post


Link to post
Share on other sites
here is a quick example I typed up:

#include <vector>
#include <iostream>

using std::vector;
using std::cout;
using std::endl;

struct foo
{
int x;
float y;
};

int main()
{
foo foofoo;
foofoo.x = 5; foofoo.y = 4.2;
vector<foo*> fooey;
fooey.push_back(&foofoo);
cout << fooey[0] << endl; //should output 32 bit address

getchar();
return 0;
}


EDIT: This is the pointer method.


[edited by - nervo on March 25, 2004 12:10:20 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by dr_slash_uh
Thanks a lot both of you. Surprisingly all my c++ book do not go into detail with vectors. I need to get a reference one.


Download this reference if you''d like: clicky (you can view it online or download the whole thing) The typical containers are string, vector, list, map.

Share this post


Link to post
Share on other sites