while loops, txt file and arrays

Hi I'm currently working on something for the future where I want to read through a comma separated txt file with a known amount of columns but not rows and I want to take each row and turn it into an array. I then want to do calculations on each array.
I was wondering if there is a method on going through a row with a while loop
to get the array and each time it passes through the loop it changes the values of the array with the next row in the file.

I know you can loop through a endless row file using this code below to stop when the file is finished this is why I am asking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

int main()
{
ifstream inputFile;
int num;

inputfile.open(val.txt)

while(inputFile >> num)
{
cout << num << endl;
}
return 0;
}


If the file was basic like

1
2
3
4
5
1
2
3
4
5


but my txt file will look like
1
2
3
1.1,1.3,15,18
2,1.5,7.3,3.5
and so on for an unknown amount of rows
Last edited on
Please don't duplicate post. See http://www.cplusplus.com/forum/beginner/278413/
Topic archived. No new replies allowed.