473,383 Members | 1,795 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,383 software developers and data experts.

Problem with vectors

I create two dimensional vector:

vector < vector< vector<int v(100);

And next I create
vector <inttemp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2

piruk
Nov 15 '07 #1
3 1186
On 15 Nov., 21:46, piruk <pira...@poczta.onet.plwrote:
I create two dimensional vector:

vector < vector< vector<int v(100);
Thats three dimensions
>
And next I create
vector <inttemp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2
v[0][0] = temp;
will do fine.

/Peter
Nov 15 '07 #2
piruk wrote:
I create two dimensional vector:

vector < vector< vector<int v(100);
Actually that's a three-dimensional one. Did you mean to have one
less 'vector' in there?
And next I create
vector <inttemp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
If your 'v' is actually two-dimensional, you just assign it
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2
You can't have a vector of 'int' "on index 0" in a vector of vectors
of vectors of int. You have to define 'v' as

vector<vector<int v(100);

then you can do

vector<inttemp(2);
temp[0] = 1;
temp[1] = 2;
v[0] = temp;
assert(v[0][0] == 1 && v[0][1] == 2);

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '07 #3
peter koch wrote:
On 15 Nov., 21:46, piruk <pira...@poczta.onet.plwrote:
>I create two dimensional vector:

vector < vector< vector<int v(100);

Thats three dimensions
>>
And next I create
vector <inttemp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2

v[0][0] = temp;
will do fine.
No, it won't. v[0] has no element with the index 0. He can only
do

v[0].push_back(temp);

with the current declaration of 'v'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '07 #4

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

Similar topics

10
by: Michael Aramini | last post by:
I need to represent 1D and 2D arrays of numeric or bool types in a C++ program. The sizes of the arrays in my intended application are dynamic in the sense that they are not known at compile time,...
5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
1
by: Dennis | last post by:
Hi I'm trying to implement a vector of vectors where find can be used to find a vector<double> in the vectors of vectors, that is hard to understand i guess. What I mean is that I got a vector...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
3
Digital Don
by: Digital Don | last post by:
I have a problem sending the Vectors as Referencial parameters..i.e. I am having a struct vector struct board { int r; int c; };
4
by: 9966 | last post by:
Greetings, I'm currently facing a problem on how to compare 2 vector's elements. For example, assuming we have declared 2 integer type vectors: vector <int> v1; vector <int> v2; and both...
4
by: demonbunny666 | last post by:
I'm trying to get this program to work, but I am running into a problem and as hard as I try I can't figure it out. It compiles fine( VS Studio 6.0) but when it executes a problem occurs, something...
2
by: joeme | last post by:
How would one using STL do the following tasks: 1) merge 2 sorted vectors with dupes, result shall be sorted 2) merge 2 sorted vectors without dupes, result shall be sorted 3) merge 2...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.