I have a file where I read data. While the data is in the linear format, but it is not straigt fowardto convert it by simply use carriage return and add comma after. My data looks like

fiield1=text
field2=tex
field1=1
field1=33
field1=432
field1=text

I have more field1 than field 2 and so on. If I convert it to csv, I can add 0 to the value of field1, assume that I have more field1 than field2. I have more than two fields.

By using ifstream to read the file and ofstream to write the csv file, how can I solve this problem?

First I write the header for the csv file

PHP Code:

fileOut
<<"Field 1,"<<"Field 2,"<<"Field 3,"<<"Field 4,"<<"Field 5";
fileOut<<endl
The problem I have is to keep reading "fileIn" for one field at a time and write the value to fileOut in a proper format