Mathematical sets using VC++

hi,

i'm new to visual c++, but i need a code really fast, that can handle mathematical sets... i was told to use STL, but i tried using a matrix for storing the sets (each row represents a set), because i don't know using STL ;(

could you help me with a code that uses STL to create/modify sets? i'm completely upset with this matrix solution... ;(
Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
The standard library has a set container class that may do what you need.

http://www.sgi.com/tech/stl/set.html

If you need more specific help, I suggest you ask a more specific question.

--efn
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
The STL's std::set is fantastic since you can create sets of objects without having to do any bit manipulation (or array addressing) yourself. Also nice because you don't have to reinvent union, intersection, or even symetric difference. The down-side is learning all about iterators (to use the set_ * algorithms); the up-side is you will know all about iterators. Here is a snippet of sample code to get you started:

#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using std::cout;
using std::endl;
using std::string;
using std::set;

enum Color {
red, orange, yellow, green, blue, indigo, violet, Color_end
};

string ColorName[] = {
"red", "orange", "yellow", "green", "blue", "indigo", "violet", "PANIC"
};

int main()
{

set<Color> s1, s2;

s1.insert(red);
s1.insert(green);
s1.insert(violet);

s2.insert(orange);
s2.insert(green);
s2.insert(indigo);

set<Color> theIntersection;
set_intersection(s1.begin(), s1.end(),
s2.begin(), s2.end(),
inserter(theIntersection, theIntersection.begin()));

string separator = "";
cout << "theIntersection = {";
for (set<Color>::const_iterator it = theIntersection.begin();
it != theIntersection.end();
++it) {
cout << separator << ColorName[*it];
separator = ", ";
}
cout << "}" << endl;

return 0;
}

Hope this helps,
-bcl
0
Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: efn {http:#9847354}