By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

stl usage question

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
dm********@yahoo.com wrote:
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

Jul 19 '05 #2

P: n/a

<dm********@yahoo.com> wrote in message
news:rB***************@newssvr22.news.prodigy.com. ..
I have an object a

class object
{
private:
string streetname ;
vector listofhomes ;
vector requires a template argument,
e.g. vector<string>
}

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

Jul 19 '05 #3

P: n/a

"Buster Copley" <bu****@none.com> wrote in message
news:bg**********@news7.svr.pol.co.uk...
dm********@yahoo.com wrote:
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.


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

class Street
{
private:
string streetname ;
vector<int> listofhomes ;
};
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.