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

filling a vector of vector

1
Hi,
It may be a simple question. But, how can i fill a vector of vector in a loop? Below is what I have tried:

std::vector< std::vector<float> > vec;
for (int i=0; i<n++; i++){
for (int j=0; j<m; j++){
//I tried the below ones. But none works.
vec[i][j]=i*j;
vec.push_back(i*j);
vec[i].push_back(i*j);
vec[i][j].push_back(i*j);
}

Thanks.
Sep 17 '06 #1
4 13798
D_C
293 100+
vec expects you to pass a vector, you are passing it an integer. Define a new vector
Expand|Select|Wrap|Line Numbers
  1. std::vector<float> vec_flt;
  2. for(){
  3.        for() {
  4.                 vec_flt.push_back((float)(i*j));
  5.               }
  6.      }
  7. // Now you can push vec_flt into vec
  8. vec.push_back(vec_flt);
I must admit, I don't know why you see it necessary to use a vector of vectors.
Sep 17 '06 #2
pra1983
10
can u tell me then how to printout the data.... from the same thing vec...

and how to traverse through the vec then....

how to pick an element or check an intermediate element from the vec.....
Oct 4 '07 #3
Ganon11
3,652 Expert 2GB
Once you build your vector of vectors, you can treat it like a 2D array when traversing and printing.
Oct 4 '07 #4
pra1983
10
Once you build your vector of vectors, you can treat it like a 2D array when traversing and printing.

actially i am trying to fill the vector with the data from a file. Can u suggest me how to fill the vector.(Is it the same way how i fill the 2D matrix).Can i use a single element of the vector from the middle of the vector at a time.Please let me know how to do that......
Oct 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
2
by: hennakapoor | last post by:
How do the form filling software determine which text field gets what data i.e. a typical form filling software will ask the user to enter the username / address / password etc. Whenever it goes to...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
3
by: crjunk | last post by:
I have a 3 table in my DataSet that I'm filling with data. After I've filled these 3 tables, I'm then trying to run a query that will fill a 4th table in the DataSet with data from the three...
5
by: utab | last post by:
Dear all, I have a function to get some string arguments. The point is that the number of these string arguments may vary. So foo(std::vector<std::string> &vec); But I want to be able to...
1
by: Carl Banks | last post by:
On Aug 22, 7:12 pm, "W. eWatson" <notval...@sbcglobal.netwrote: There's nothing built in, but see the bisect module. It is a good way to determine which interval you are in, and you can...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.