Hi there,
I have a function called
fillRow(parameter1, parameter2)
. The first parameter is an
int
and the second is a
string
.
I'll try and expalin this as briefly as possible. I want this function to fill rows with data that is read from multiple files. Each file's data is placed in a row. The int is the row number and the string is the pathname of the file. If I manually enter values in (e.g.
fillRow(0, pathname)
where
string pathname = "C:\\test.txt"
) it works fine. However, I want to 'automate' my program.
So I'm trying to do this using
for
. This is what I've been trying:
1 2 3 4
|
ifstream filein("C:\\FileList.txt");
for (string line; getline(filein, line);)
fillRow(0, line);
filein.close()
|
Now, the file 'FileList.txt' has a file's pathname on each line. Each line (i.e. pathname) is passed into the fillRow() function. The int paramater has been set to zero for now but I need this to change with each line that contains its unique pathname. With this code above, row zero displays the data from the last file pathname that is found in 'FileList.txt'. I believe that this is because every row of data is written over until the last line in 'FileList.txt' is read.
I tried this code but I was unsuccessful:
1 2 3 4 5
|
ifstream filein("C:\\FileList.txt");
int j;
for (j = 0, string line; j<10, getline(filein, line), j++;)
fillRow(j, line);
filein.close()
|
That is, j is representing line numbers in 'FileList.txt'. This also means that j represents row numbers. I hope this makes sense.
So how could I go about making this idea work? Have I provided you with enough information?
Thanks for reading this post and anu advice / ideas would be great!!