push_back error

So I've been trying to run the simple program below using code:blocks with windows 7 64 bit and after I click "build and run" the program opens and a screen appears saying windows is searching for solutions to fix this problem. And on the command prompt it says "Process returned 255 (0xFF)". Why I am I getting this error?

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <vector>

using namespace std;

int main()
{
     vector< vector<string> > array;
     array[0].push_back("Diff");
    cout << "Hello world!" << endl;
    return 0;
}
Last edited on
You are accessing a vector<string> that doesn't exist (array is empty).
So, either construct array with a size or push_back a vector before accessing array[0].
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <vector>

using namespace std;

int main()
{
     vector< vector<string> > array(10);//creat 10 vector<vector<string>>
     //or array.push_back(vector<string>());
     array[0].push_back("Diff");
    cout << "Hello world!" << endl;
    return 0;
}
Topic archived. No new replies allowed.