Can someone teach me what's the error in my code? The exception is thrown at line ifs >> Acc[i].num_followers;
. Am I facing any pointer issues?
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct Followers {
string title = "", tag = "";
int num_followers = 0;
};
void readInput(Followers Acc[], int& totalAccount) {
ifstream ifs("Followers.txt");
for (int i = 0; !ifs.eof(); i++) {
getline(ifs, Acc[i].title);
getline(ifs, Acc[i].tag);
ifs >> Acc[i].num_followers;
totalAccount += 1;
}
}
int main() {
Followers acc[5];
int total = 0;
readInput(acc, total);
cout << total;
return 0;
};
This is the text file.
Instagram
@instagram
290000000
Cristiano Ronaldo
@cristiano
160000000
The Rock
@therock
137000000
Ariana Grande
@arianagrande
150000000
Selena Gomez
@selenagomez
148000000