Was just wondering how would I go about looking at a value
within a vector.... which is inside another vector?
would it be vector[vector[i]];???
completely confused....




Posted 15 November 2007 - 02:00 PM
Posted 15 November 2007 - 02:04 PM
vector<vector<double> > myVector(4,vector<double>(4,0.0)); //creates 4x4 nested vector vector<double> myRow=myVector[1]; //returns a reference to myVector[1], and assigns this vector to myRow double myValue=myRow[3]; //returns a reference to myRow[1], and assigns it to myValue
double myValue=myVector[1][3];
This post has been edited by jjhaag: 15 November 2007 - 02:14 PM
Posted 15 November 2007 - 02:40 PM
This post has been edited by ShinX: 15 November 2007 - 02:44 PM
Posted 16 November 2007 - 08:25 AM
void input(vector<vector<int> > &votes)
{
string next;
int myint;
while(getline (cin,next))
{
stringstream(next) >> myint;
if(!isspace(myint)){
votes.push_back(vector<int>(myint));
}
}
}
int main()
{
vector<vector<int> > votes;
input(votes);
//cout << "Total Votes: " << votes.size();
for(int i = 0; i< votes.size(); i++){
vector<int> myRow=votes[i];
int myValue=myRow[i];
//int myValue=votes.at(i)[j];
cout << myValue;
}
This post has been edited by ShinX: 16 November 2007 - 08:26 AM
Posted 16 November 2007 - 12:54 PM
vector<vector<int> > myVector;
int num;
for (int i=0; i<4; ++i) {//controls number of rows to be inputted
myVector.push_back(vector<double>);//adds an empty row to the end of the vector
for (int i=0; i<4; ++i) {//controls number of columns to be inputted
cin >> num;
myVector.push_back(num);//adds element to the current row
}
}
for (int i = 0; i< votes.size(); i++) {
for (int j = 0; j< votes.size(); j++) {
cout << myVector.at(i).at(j) << " ";
}
cout << endl;
}
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
