I am writing a function that requires me to turn a file into an array of 0s and 1s. I figured this was most easily accomplished using a bool
array. However, the below code fails and crashes for files larger than ~1MB. My machine has 8GB RAM, so I see no reason for the crash.
string file_name;
cin >> file_name;
string text = read_file(file_name); //I have defined this function as returning a string containing the file's contents and it works fine when tested separately
int length = text.size();
bool bin_arr[8*length]; //to store 0s and 1s
The initialisation of bin_arr
fails, and the program simply exits.
I will be handling files larger than 1GB or so. However, I have no idea why this is happening. I am fairly new to C++.
In case it is relevant, I am on Windows 10, using GCC version 6.3.0.