I would like to read in a *.csv file into an array defined as 24 x 24, but not sure how to do it. The name of the file is Currency Exchange Rates.csv. Can I use the file using this name, or should I change its name before working with it?
I would like to read in a *.csv file into an array defined as 24 x 24, but not sure how to do it. The name of the file is Currency Exchange Rates.csv. Can I use the file using this name, or should I change its name before working with it?
You could always read the answer I posted the last time you asked this question.
I looked at this answer and am still a bit confused. I am including 48 records below as sample data.
1.0000000,0.7785980,0.3613370,1.8514000,0.8285000, 0.1208240,0.1747490,1.2982000,0.1285890,0.0222220, 0.0095940,0.2631580,0.0881680,0.7086020,0.1596320, 0.6046680,0.1658810,0.0009350,0.0095350,0.1447010, 0.8553590,0.0306420,0.0249000,0.0005220
1.2843600,1.0000000,0.4640870,2.3778600,1.0640900, 0.1551820,0.2244400,1.6673600,0.1651550,0.0285410, 0.0123220,0.3379890,0.1132390,0.9101000,0.2050250, 0.7766110,0.2130520,0.0012010,0.0122460,0.1858480, 1.0985900,0.0393550,0.0319810,0.0006710
If it's just a long list of floating-point values separated by a comma, you really don't need to do more than this:
Code:for (int i = 0; i < 24; i++) { for (int j = 0; j < 24; j++) { in>> array[i][j]; // You can add error checking for the expected // comma here if you really want to. in.ignore(); } }
My best code is written with the delete key.
>The name of the file is Currency Exchange Rates.csv. Can I use the file using this name
Sure, just put this in front of Prelude's code to open the file for reading:
Code:ifstream in( "Currency Exchange Rates.csv" );
I assume the values have a particular order to them, you may want to confirm that order. Otherwise all you have is a whole lot of floats.