STL question - an array of sets

P

Phil

Hello,

I'm trying to create an array of sets using the STL library, so far without
success. This is an example of many ideas that I have tried and I have
searched the Internet for an answer

Vector <set <int> > vset();

Vset[0].insert(3);

It's the insert statement that's causing the compiler errors. I'm also
receiving error messages when I try a similar scheme to display the set
contents.

This is causing what little hair I have left to fall out. Can anyone help?
 
?

=?ISO-8859-15?Q?Stefan_N=E4we?=

Phil said:
Hello,

I'm trying to create an array of sets using the STL library, so far without
success. This is an example of many ideas that I have tried and I have
searched the Internet for an answer

Vector <set <int> > vset();

Vset[0].insert(3);

It's the insert statement that's causing the compiler errors. I'm also
receiving error messages when I try a similar scheme to display the set
contents.

This is causing what little hair I have left to fall out. Can anyone help?

Please post a minimum compilable example and the exact
error message.

/S
 
M

mlimber

Phil said:
Hello,

I'm trying to create an array of sets using the STL library, so far without
success. This is an example of many ideas that I have tried and I have
searched the Internet for an answer

Vector <set <int> > vset();

Vset[0].insert(3);

It's the insert statement that's causing the compiler errors. I'm also
receiving error messages when I try a similar scheme to display the set
contents.

This is causing what little hair I have left to fall out. Can anyone help?

The compiler errors are probably a result of the capital V's on Vset
and Vector. You declared the former with a lowercase v and the latter
must have lowercase letters. Once you fix that, you will find that it
doesn't work because your vector is zero length. Do something like
this:

vector< set<int> > vset( 10 ); // ten sets
vset[ 0 ].insert( 3 ); // Insert into the first set
vset[ 9 ].insert( 5 ); // Insert into the last set

Cheers! --M
 
J

Jeff Flinn

Phil said:
Hello,

I'm trying to create an array of sets using the STL library, so far
without success. This is an example of many ideas that I have tried
and I have searched the Internet for an answer

Vector <set <int> > vset();

Vset[0].insert(3);

It's the insert statement that's causing the compiler errors. I'm also
receiving error messages when I try a similar scheme to display the
set contents.

Note that C++ is case sensitive, and namespace sensitive for that matter.
Assuming your actual code has the proper case and namespace scoping via
std:: and/or appropriate using declarations, your problem is that your
vector is empty. Your snippet above should be:

std::vector< std::set< int > > vset(1);

vset[0].insert(3);

// append another empty sets

vset.push_back( std::set<int>() );

vset[1].insert(4);

Jeff Flinn
 
A

Andre Kostur

Hello,

I'm trying to create an array of sets using the STL library, so far
without success. This is an example of many ideas that I have tried and I
have searched the Internet for an answer

Vector <set <int> > vset();

Vset[0].insert(3);

It's the insert statement that's causing the compiler errors. I'm also
receiving error messages when I try a similar scheme to display the set
contents.

This is causing what little hair I have left to fall out. Can anyone help?

In addition to the casing issue that other have metioned (vector vs.
Vector, and vset vs. Vset), your variable declaration isn't a variable
declaration. That's a function declaration. You're declaring a function
named "vset" which takes no parameters, and returns a vector of sets of
int by value. Drop the parentheses.
 
P

Phil

Thank you for the very prompt replies, I hadn't subscribed to a news group
until now and didn't know what to expect. As a consequence I over simplified
the problem which is really based around a two dimensional array. The upper
case characters were due to a Microsoft problem. Anyway, after simplifying
the problem the real fault is in the initialisation of the sets and I'll
post a separate question after I've thought about it a bit longer.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top