GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Apr-2004, 03:00
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road

vector of vectors/arrays


im a bit stuck here guys what i am trying to do is read a line from a file then store it in a vector or array. i then want to store each of these lines separately in a vector.say store the first line on position 1 in the vector
what i have is this:

CPP / C++ / C Code:
#include "stdafx.h"
#include <iostream>
#include <vector>

using namespace std;


vector <int> V;
vector <V> S;

int main(int argc, char* argv[])
{

	V.push_back(1);
	V.push_back(2);
	V.push_back(3);
	V.push_back(4);
	V.push_back(5);
	V.push_back(6);

	S.push_back(V);
	return 0;
}
  #2  
Old 15-Apr-2004, 03:32
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
So what is it that you need help with? What problem are you running into?
__________________
-Aaron
  #3  
Old 15-Apr-2004, 03:37
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by aaroncohn
So what is it that you need help with? What problem are you running into?

i am getting two errors :

H:\vectors\vectors.cpp(12) : error C2974: 'vector' : invalid template argument for '_Ty', type expected

and this one:

H:\vectors\vectors.cpp(24) : error C2664: 'push_back' : cannot convert parameter 1 from 'class std::vector<int,class std::allocator<int> >' to 'const int &'

any ideas
  #4  
Old 15-Apr-2004, 03:47
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Looks like this is causing the problem.

CPP / C++ / C Code:
vector <V> S;
V is a variable of type vector. Vector is looking for a data type between the two karats, not a variable.
__________________
-Aaron
  #5  
Old 15-Apr-2004, 03:51
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by aaroncohn
Looks like this is causing the problem.

CPP / C++ / C Code:
vector <V> S;
V is a variable of type vector. Vector is looking for a data type between the two karats, not a variable.

so how do u reckon i should go about it then what the correct way of declaring vector of vector
  #6  
Old 15-Apr-2004, 12:25
machinated machinated is offline
Awaiting Email Confirmation
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
i posted this in a thread a while ago:

his is how u would declare a 2 dim vector:
vector < <vector <int> >matrix; (make sure you have spaces jus like i did)

altho i do believe that with multidimensional vectors you need to create rows and then assign values with push_back();
for example matrix.push_back(vector <int>()); would create the row
matrix[0] and so on. to assign values: jus go matrix[0].push_back(50); which assigns 50 to matrix[0][0]. another matrix[0].push_back(100); would assign 100 to matrix[0][1] and so on. You can access the elements in regular fashion: matrix[0][0]; matrix[1][0]; and so on. do some experimenting with this till you are comfortable.
hope that helps
  #7  
Old 15-Apr-2004, 22:20
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by machinated
i posted this in a thread a while ago:

his is how u would declare a 2 dim vector:
vector < <vector <int> >matrix; (make sure you have spaces jus like i did)

altho i do believe that with multidimensional vectors you need to create rows and then assign values with push_back();
for example matrix.push_back(vector <int>()); would create the row
matrix[0] and so on. to assign values: jus go matrix[0].push_back(50); which assigns 50 to matrix[0][0]. another matrix[0].push_back(100); would assign 100 to matrix[0][1] and so on. You can access the elements in regular fashion: matrix[0][0]; matrix[1][0]; and so on. do some experimenting with this till you are comfortable.
hope that helps

thanks but i wanted to create a vector in which i store rows of several structures. i got it it was

CPP / C++ / C Code:
vector < int > V;
vector < vector < int > > S;

  #8  
Old 18-Apr-2004, 09:26
dany_apache dany_apache is offline
New Member
 
Join Date: Apr 2004
Posts: 4
dany_apache is on a distinguished road
Hi i think i've a similiar problem but i can't solve it as you told :-(

i'm working with a ppm file and i should make an interpolation getting a ppm of double size. As all the ppm file the pixels's values are stored in a such king of matrix [red][green][blue] and i've saved them using a class image
CPP / C++ / C Code:
immagine::immagine(int n_righe, int n_colonne)
{
	id=P6;
	width=n_righe;
	height=n_colonne;
	image=new Pixel[n_righe*n_colonne];
}
so now i would create a 2d vector to store the data and work on them...

using :
Quote:
Originally Posted by vadharah
thanks but i wanted to create a vector in which i store rows of several structures. i got it it was

CPP / C++ / C Code:
vector < int > V;
vector < vector < int > > S;


as i did:

CPP / C++ / C Code:
int immagine::GetPixel()
{
	image=new Pixel[height*width];
	vector<int> V;
	vector<vector<int>> S;

	return true;
}
i get the following errors:

Compiling...
immagine.cpp
error C2146: syntax error : missing ',' before identifier 'S'
error C2065: 'S' : undeclared identifier
error C2143: syntax error : missing '>' before ';'

Error executing cl.exe.

immagine.obj - 3 error(s)


how can i do this?
Last edited by dsmith : 18-Apr-2004 at 11:12. Reason: Use [c] & [/c] for syntax highlighting.
  #9  
Old 18-Apr-2004, 11:08
machinated machinated is offline
Awaiting Email Confirmation
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
try fixing the spaces in that vector declaration. you should have spaces before and after all the < and > jus like the guy who posted the vector declaration of structures.
  #10  
Old 18-Apr-2004, 12:55
dany_apache dany_apache is offline
New Member
 
Join Date: Apr 2004
Posts: 4
dany_apache is on a distinguished road
yes it was soooo simple thanks!!!

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:41.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.