Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I have included the STL library in Arduino and i can run a program with 1D vector. But i am getting error while declaring a 2D vector.

#include <StandardCplusplus.h>
#include <serstream>
#include<vector>
#include<iterator>

using namespace std;

vector <vector<int> > grid;
vector<int> col(5,3);
grid.push_back(col);

void setup()
{
    Serial.begin(9600);
}

void loop()
{
  for(int i = 0; i < 5; i++)
  {
    Serial.println(grid[[0][i]);
  }
}

And the error is

'grid' does not name a type.   

Do i need to add another header file?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The error is coming from

 grid.push_back(col);

You cannot have this line at the top-most level outside a function / main. Move it inside setup or loop.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.