473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

STL two dimensional array of sets question

Hello,

Yet another question I'm afraid. I'm trying to construct a two dimensional
array of sets (9 X 9).

The first line of code gives me a single array of nine sets and the second
line is my feeble attempt to expand the first line to a two dimensional
array of sets.

vector< set<int setOne(9); // 9 sets

vector< vector<int setTwo<int test(81); // 9 X 9 sets

I've tried all sorts of combinations without success. Can someone tell me
where I've gone wrong?

In case I haven't explained this very well, this is what I'm trying to
achieve for example:

setTwo[0][0].insert(2)

--
Regards,
Phil.
Jul 15 '06 #1
2 2104
Phil wrote:
Hello,

Yet another question I'm afraid. I'm trying to construct a two dimensional
array of sets (9 X 9).

The first line of code gives me a single array of nine sets and the second
line is my feeble attempt to expand the first line to a two dimensional
array of sets.

vector< set<int setOne(9); // 9 sets

vector< vector<int setTwo<int test(81); // 9 X 9 sets

I've tried all sorts of combinations without success. Can someone tell me
where I've gone wrong?
Well, if you want a set of int named x, you write:

set<intx;

If you want a vector of set of int, you write:

vector<set<int x;

So if you want a vector of vector of set of int, it must be:

vector<vector<set<int x;

To initialize it with 9x9 sets, you'd need something like:

vector<vector<set<int setTwo(9, vector<set<int(9));

This will create a vector of 9 vectors, each of which contains 9 sets of
int.

Jul 15 '06 #2
Phil wrote:
Hello,

Yet another question I'm afraid. I'm trying to construct a two dimensional
array of sets (9 X 9).

The first line of code gives me a single array of nine sets and the second
line is my feeble attempt to expand the first line to a two dimensional
array of sets.

vector< set<int setOne(9); // 9 sets

vector< vector<int setTwo<int test(81); // 9 X 9 sets
#include <set>
#include <vector>
using namespace std;

vector< vector< set<int vvs;

int main(){
set<ints1, s2
set<int>::iterator si;
vector<set<int vs;

s1.insert(12354);
s2.insert(3244);
vs.push_back(s1);
vs.push_back(s2);
vvs.push_back(vs);
vvs[0][1].insert(5466);
si=vvs[0][1].find(3244);
}

The above isn't a 9x9 array yet, but a 1x2. To make it 9x9, you'll have
to create 9 vectors of each 9 sets, and add them to vvs.

Jul 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: smurf | last post by:
Seems a simple question, but I can't find a simple answer: I have created a two dimensional array. I wish to send the data, a row at a time to a graph plotting routine which is expected a one...
4
by: Todd | last post by:
I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm using a select sort for 1 dimensional arrays but it is not working for a 2 dimensional array. The 2 dimensional array are...
2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
6
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
5
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.