Answer:
Code explained below
Step-by-step explanation:
#include<fstream>//header file for file stream
using namespace std;
//your just need to add this function and
//call it after the declaration of array it will
//load the from the file into your array
//Function to read data from the file.
void readDataFromFile(int arr[], int size){
fstream fin;//creating a file stream object.
//opening the file in reading mode(fstream::in is for read mode).
fin.open("file_name.txt",fstream :: in);
//loop to store the data from the file to the array.
for(int i = 0; i < size; i++){
//we can use fin to load the data from file to array
//just like cin loads data from console into variables.
fin >> arr[i];
}
}
//program to read data from the .txt file
int main(){
//array of size 1000
const int size = 1000;
int arr[size];
//read data from the file
readDataFromFile(arr,size);
}