How to read file and calculate data

Hey, I am new to C++ and I have this project I need to do for class. I am given two .csv files and I have to use the data in them to calculate certain things. My question is what is the syntax for reading the data and assigning the variables for each row to do my calculations?

There are 50 lines of data in this format: 795696 1255925 22717 2074338 AL

So far I got code to actually read the file and simply output the contents of the file. I also made 5 variables, 4 ints for the 4 numbers and a string for the initials at the end.

1
2
3
4
5
6
7
8
9
10
11
12
13

  int main()
    {
  string line;
  ifstream elect12 ("elect12.csv");
  if (elect12.is_open())
  {
    while ( getline (elect12,line) )
    {
      cout << line << '\n';
    }
    elect12.close();
  }
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
int a, b, c, d
string e

while( elect12 >> a >> b >> c >>d >> e)
{
   // processing goes her
}
Topic archived. No new replies allowed.