I'm trying to read a file line by line and insert the lines into an array, but it won't compile. I'm using VS code and it highlights arr[line] and when I hover over it is says "no operator "[]" matches these operands". Can someone tell me what I'm doing wrong?
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main() {
char arr[4];
string line;
ifstream file;
file.open("input.txt");
if(file.is_open()) {
while (getline(file, line))
{
file >> arr[line]; // the problem is with this line
}
file.close();
}
return 0;
}