what is the meaning about std :: vector < std :: vector <double> > COOR ;

// read the coordinates
std :: vector < std :: vector <double> > COOR ;//????????????
for (int Node = 0 ; Node < Rows ; Node++ ){
COOR.push_back(std :: vector <double> () );
for (int j = 0 ; j < 3 ; j++){
if (MyFile){
MyFile >> number ;

if ( j < 3-1 ){
MyFile.get(a) ;
// MyFile.get(b) ;
// MyFile.get(c) ;
// MyFile.get(d) ;
// MyFile.get(e) ;
// MyFile.get(f) ;
// MyFile.get(g) ;
}
}
else {
std :: cout << "Error1" << std :: endl ;
}
COOR[Node].push_back(number) ;
}
}
It’s a dynamic 2D array.
Please use a source code tag which is this one [code] for a readable question.
That is a 2D vector (array) of double type. It is basically a vector of vectors.
That line creates an EMPTY 2D vector. Zero rows, zero columns

The first for loop adds blank vectors as rows.

The second for loop adds 3 column elements to each row, each one read from a file(?)

The number of rows and columns in your snippet are known, the 2D vector could be sized on creation:

std::vector<std::vector<double>> COOR(Rows, std::vector<int>(3));

This creates a 2D vector that is zero-filled.

Changing the elements is then done using operator[] or std::vector's at() member function.

COOR[1][0] = 3.14159;

COOR.at(1).at(0) = 3.14159;
Last edited on
Registered users can post here. Sign in or register to post.