I have a text file with inside made of:
3
7 8 9 7 8
5 7 9 5 7
6 8 7 9 7
I have set 3 to int 'd'. All other lines should belong to int 'b'. But it seems that 'b' still counts in the first line, which became 0 after extracting it to 'd'.
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int b, d;
string line;
ifstream file("File.txt");
if(!file.is_open())
cout << "File failed to open." << endl;
file >> d;
while(getline(file, line))
{
istringstream iss(line);
double v = 0;
while(iss >> b)
v += b;
cout << v / 5 << endl;
}
return 0;
}
It outputs:
0
7.8
6.6
7.4
What could I do to fix this ? Thank you in advance :)