Segmentation fault

I get a Segmentation fault when i try to fill this vector up this is literally my first go at using them so I cant figure out what I did wrong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#include<iostream>	
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
using namespace std;

//======================================================================




int main () { 

//FILLING DATA ARRAYS 
// ask user for dat file
 
	ifstream dat;
	do {
		cout << "Input filename where the raw data exist-->";
		char filename [50];
		cin.getline(filename,50);
		dat.open(filename);
		if (!dat.is_open())
		cout << "File Does Not Exist!" << endl ;
	} while (!dat.is_open());

	vector<vector<double> > data;
	int x;
	double  a,b,c,d,e,f;

	while (	dat >> a >> b >> c){

		data[x][0] = a;
		data[x][1] = b;
		data[x][2] = c;

		cout << data[x][2] << endl;
		x++;
	}
	

return (0);
}
By default vector is empty and hold 0 values. Either do .resize() or .push_back()
Last edited on
Topic archived. No new replies allowed.