"segmentation fault.core dumped"

i don't know how to solve this , can anyone help me please?
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
46
47
48
49
50
51
52
53
54
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>>litTableauInt(string volumes_d_eau_distribues,int nb_colonnes){
    ifstream f("volumes_d_eau_distribues.txt");
   vector<vector<int>>t;
   int x;
   if(f){
   while(f){
    for(int i=0;i<50;i++)
        for(int j=0;j<nb_colonnes;j++){
            if(f){

                f>>x;
                t[i][j]=x;

            }
        cout<<endl;
        }
    }f.close();
      return t;

}}

vector<int>colonne(vector<vector<int>>t,unsigned int i){
    vector<int> col;
    int x=0;
    for(unsigned int k=0;k<t.size();k++)
        for(unsigned int j=0;j<t[k].size();j++)
            if(j==i)
                col[x++]=t[k][i];
return col;
}

int total(vector<int> t){
    int somme=0;
    for(unsigned int i=0;i<t.size();i++)
        somme=somme+t[i];
    return somme;
}

int main() {
vector<int>t;
ifstream f("volumes_d_eau_distribues.txt");

return total(colonne(litTableauInt("volumes_d_eau_distribues.txt",2),2));

f.close();

}
Last edited on
closed account (48T7M4Gy)
Bonjour,

http://stackoverflow.com/questions/2346806/what-is-segmentation-fault
http://www.cplusplus.com/doc/tutorial/files/

while(f){ :(

while(f>>x){ :)
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/179814/
Line 10: The vector t is empty. You cannot access it like on line 19. You need to use push_back() or alternatively resiize():

http://www.cplusplus.com/reference/vector/vector/push_back/
http://www.cplusplus.com/reference/vector/vector/resize/

It is also possible to create the vector with a certain size:

http://www.cplusplus.com/reference/vector/vector/vector/
Topic archived. No new replies allowed.