When I try to run this I get a segmentation fault:
#define FILE_NAME "test.html"
#define STRING_ARRAY_SIZE 1000000
int main() {
fstream file;
string line = "";
string string_array [STRING_ARRAY_SIZE];
int i = 0;
file.open(FILE_NAME);
while(getline(file, line)) {
string_array[i] = line;
i++;
cout << line << endl;
}
file.close();
}
Instead, when I try to compile this, it works:
#define FILE_NAME "test.html"
#define STRING_ARRAY_SIZE 100000
int main() {
fstream file;
string line = "";
string string_array [STRING_ARRAY_SIZE];
int i = 0;
file.open(FILE_NAME);
while(getline(file, line)) {
string_array[i] = line;
i++;
cout << line << endl;
}
file.close();
}
Turns out, the only difference is the size of the array. Why does it work when it is 100000, and it does not when it is 1000000? What is the maximum size? Thank you.
See Question&Answers more detail:os