stl usage question

G

Guest

I have an object a

class object
{
private:
string streetname ;
vector listofhomes ;
}

i want to use STL template to build a program like

this class will have a

{ reed street,
list of houses in this street( names).
}

I want this to be collection. Like
{ streetname, list of houses)
(streetname, list of houses)...

How do i do it ?


Thanks in advance.

jk
 
B

Buster Copley

I have an object a

class object
{
private:
string streetname ;
vector listofhomes ;
}

That's almost a class declaration. (You need a semicolon after
the closing brace.) It is not an object.
i want to use STL template to build a program like

Read through your writing before you publish it. People are
more likely to understand your question if it makes sense.
this class will have a

{ reed street,
list of houses in this street( names).
}
What?

I want this to be collection. Like
{ streetname, list of houses)
(streetname, list of houses)...

That's a very odd syntax. What does it mean?
How do i do it ?

Overload `operator >>' for objects of your class type. In your
`main ()' function, declare an object of type std::vector <object>.
Use std::copy, std::istream_iterator and std::back_inserter to read
the objects from a stream (either cin or an istream object you have
created) and insert them into the vector.
Thanks in advance.

jk

Regards,
Buster
 
M

Mike Wahler

I have an object a

class object
{
private:
string streetname ;
vector listofhomes ;

vector requires a template argument,
e.g. vector said:
}

i want to use STL template to build a program like

this class will have a

{ reed street,
list of houses in this street( names).
}

I want this to be collection. Like
{ streetname, list of houses)
(streetname, list of houses)...

How do i do it ?

vector<object> collection;

Alos I think you should have a more descriptive name
for your class than 'object', perhaps 'Street' or
'Houses', etc.

Which C++ book(s) are you reading?

-Mike
 
J

John Harrison

Buster Copley said:
That's almost a class declaration. (You need a semicolon after
the closing brace.) It is not an object.

Also needs a type parameter after vector, e.g.

class Street
{
private:
string streetname ;
vector<int> listofhomes ;
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

template with STL container 10
STL Vector question? 12
Street address parsing in Python, again. 1
STL list Usage 7
Sorting an STL map 1
c++ stl 37
stl in c++ 2
wrapping std::vector<> to track memory usage? 7

Members online

Forum statistics

Threads
474,138
Messages
2,570,801
Members
47,348
Latest member
nethues

Latest Threads

Top