int main()
{
const int T[2] = {5,10};
const int N = 10;
for (int i=0; i<=1; i++)
{
double F[N*T[i]] = {0};
}
return 0;
}
--To view this discussion on the web visit https://groups.google.com/d/msg/egi-programming-and-r/-/zEgKgmJIlHkJ.
You received this message because you are subscribed to the Google Groups "EGI programming and R" group.
To post to this group, send email to egi-progra...@googlegroups.com.
To unsubscribe from this group, send email to egi-programming-...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/egi-programming-and-r?hl=en.
#include <iostream>
#include <vector>
using namespace std;
int main (int argc, const char * argv[])
{
const int T[2] = {5,10};
const int N = 10;
//setup an empty vector of vector<double> ptrs to hold the references to the vectors that get created.
vector<vector<double>*> vector_of_ptrs;
for (int i=0; i<=1; i++) {
//create a vector ptr to hold the ref to the newly created dynamic sized vector of doubles
// note: values of the first vector will have 0 values & the second will have 1 values depending on the i value from the above for.
vector<double>* ref_to_new_vector = new vector<double>(N*T[i],i);
//add the ref of the new vector to our ptrs vector. -> changed value of initialise to differentiate the vectors
vector_of_ptrs.push_back(ref_to_new_vector);
// OR i could write the above as
// vector_of_ptrs.push_back(new vector<double>(N*T[i],i));
}
// now with the created vector references stored in the vector_of_ptrs
// use an iterator (could be a manual index here but iterators do all this work for us!
// http://www.cplusplus.com/reference/stl/vector/begin/
// http://stackoverflow.com/questions/409348/iteration-over-vector-in-c
for ( vector<vector<double>*>::iterator it=vector_of_ptrs.begin() ; it < vector_of_ptrs.end(); it++ ) {
// dereference the iterator to get the ref of the stored vector
vector<double>* the_vector_that_was_stored = *it;
//use the -> operator to use the 'type' / cast the var into it's type (a vector) instead of it's current form a ptr!
cout << "The size of the vector is: " << the_vector_that_was_stored->size() << "\n";
for ( vector<double>::iterator it_2=the_vector_that_was_stored->begin() ; it_2< the_vector_that_was_stored->end(); it_2++ ) {
// you have to cast the values to force them into cout
// OR store them in a typed var (cast is implied) double the_value = *it_2;
cout << "The value of the item stored in the vector is: " << double(*it_2) << " and the position in the vector is : " <<
int(it_2 - the_vector_that_was_stored->begin()) << "\n";
}
}
return 0;
}
To post to this group, send email to egi-programming-and-r@googlegroups.com.
To unsubscribe from this group, send email to egi-programming-and-r+unsub...@googlegroups.com.
To post to this group, send email to egi-programming-and-r@googlegroups.com.
To unsubscribe from this group, send email to egi-programming-and-r+unsub...@googlegroups.com.
To post to this group, send email to egi-programming-and-r@googlegroups.com.
To unsubscribe from this group, send email to egi-programming-and-r+unsub...@googlegroups.com.